Book Image

Node.js Design Patterns - Second Edition

By : Luciano Mammino, Purra, Mario Casciaro
Book Image

Node.js Design Patterns - Second Edition

By: Luciano Mammino, Purra, Mario Casciaro

Overview of this book

Node.js is a massively popular software platform that lets you use JavaScript to easily create scalable server-side applications. It allows you to create efficient code, enabling a more sustainable way of writing software made of only one language across the full stack, along with extreme levels of reusability, pragmatism, simplicity, and collaboration. Node.js is revolutionizing the web and the way people and companies create their software. In this book, we will take you on a journey across various ideas and components, and the challenges you would commonly encounter while designing and developing software using the Node.js platform. You will also discover the "Node.js way" of dealing with design and coding decisions. The book kicks off by exploring the basics of Node.js describing it's asynchronous single-threaded architecture and the main design patterns. It then shows you how to master the asynchronous control flow patterns,and the stream component and it culminates into a detailed list of Node.js implementations of the most common design patterns as well as some specific design patterns that are exclusive to the Node.js world.Lastly, it dives into more advanced concepts such as Universal Javascript, and scalability' and it's meant to conclude the journey by giving the reader all the necessary concepts to be able to build an enterprise grade application using Node.js.
Table of Contents (12 chapters)

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "ES2015 introduces the let keyword to declare variables that respect the block scope."

A block of code is set as follows:

const zmq = require('zmq')
const sink = zmq.socket('pull');
sink.bindSync("tcp://*:5001");

sink.on('message', buffer => {
  console.log(`Message from worker: ${buffer.toString()}`);
});

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

 function produce() {
   //...
   variationsStream(alphabet, maxLength)
     .on('data', combination => {
       //...
       const msg = {searchHash: searchHash, variations: batch};
       channel.sendToQueue('jobs_queue', 
new Buffer(JSON.stringify(msg)));
       //...
     })
   //...
 }

Any command-line input or output is written as follows:

node replier
node requestor

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "To explain the problem, we will create a little web spider, a command-line application that takes in a web URL as the input and downloads its contents locally into a file."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.