HomeBlogDigestBooksProjectsArchiveAboutlogo

A Curious Animal

Born to be curious, born to be animal!

Graceful shutdown NodeJS HTTP server when using PM2

27 August, 2017
- 5 min read

So you have created a NodeJS server that receives tons of requests and you are really happy but, as every piece of software, you found a bug or add a new feature to it. It is clear you will need to shutdown your NodeJS process/es and restart again so that the new code takes place. The question is: **how can you do that in a graceful way that allows continue serving incoming requests?**

Using PM2 to manage NodeJS cluster

20 August, 2017
- 5 min read

The cluster module allows us to create worker processes to improve our NodeJS applications performance. This is specially important in web applications, where a master process receives all the requests and load balances them among the worker processes. But all this power comes with the cost that must be the application who manages all the complexity associated with process managements: what happens if a worker process exists unexpectedly, how exit gracefully the worker processes, what if you need to restart all your workers, etc. In this post we present [PM2](http://pm2.keymetrics.io) tool. although it is a general process manager, that means it can manage any kind of process like python, ruby, ... and not only NodeJS processes, the tool is specially designed to manage NodeJS applications that want to work with the cluster module.

Using cluster module with HTTP servers

18 August, 2017
- 5 min read

The [cluster](https://nodejs.org/api/cluster.html) module allow us improve performance of our application in multicore CPU systems. This is specially important no matter if working on an APIs or an, i.e. ExpressJS based, web servers, what we desire is to take advantage of all the CPUs on each machine our NodeJS application is running. The cluster module allow us to load balance the incoming request among a set of worker processes and, because of this, improving the throughput of our application. In the previous post [Understanding the NodeJS cluster module]({{ site.baseurl }}{% post_url 2017-08-12-understanding-the-nodejs-cluster-module %}) I introduced the cluster module and show some basic usages of it to create worker processes and comunicate them with the master process. In this post we are going to see how to use the cluster module when creating HTTP servers, both using plain [HTTP](https://nodejs.org/api/http.html) module and with ExpressJS.

Understanding the NodeJS cluster module

12 August, 2017
- 8 min read

NodeJS processes runs on a single process, which means it does not take advantage from multi-core systems by default. If you have an 8 core CPU and run a NodeJS program via `$ node app.js` it will run in a single process, wasting the rest of CPUs. Hopefully for us NodeJS offers the [cluster](https://nodejs.org/api/cluster.html) module that contains a set of functions and properties that help us to create programs that uses all the CPUs. Not a surprise the mechanism the cluster module uses to maximize the CPU usage was via forking processes, similar to the old [fork()](http://www.includehelp.com/c-programs/c-fork-function-linux-example.aspx) system call Unix systems.

fetch API and Express sessions

11 December, 2016
- 4 min read

*TL;DR* fetch API is the successor of XHR and although it's really powerful ( see [What is the difference between the Fetch API and XMLHttpRequest?](http://stackoverflow.com/questions/35549547/what-is-the-difference-between-the-fetch-api-and-xmlhttprequest)) you should take care of some things, like the fact you are responsible to determine if cookies must be sent to the server.

Configuring Atom editor with ESLint and the AirBnB style guide rules

14 August, 2016
- 5 min read

TL;DR This article demonstrate how to integrate the ESLint tool with Atom editor so our source code be automatically checked, showing linting messages in editor. In addition, ESLint will be configured based on the AirBnB code style rules.Atom & ESLintAtom editor is probably one of the most used text editors (along with SublimeText, Visual Studio Code, TextMate, ...). On his side, ESLint is an open source project, originally created by Nicholas C. Zakas, with the goal to provide a pluggable…