PM2 the missing node.js process manager

Long time I’ve searched for a NodeJS process manager that keep our script alive forever, ensure that our service and the worker restarted when the server restarted. I mean in a seamless and beautiful way.

So finally the team from keymetrics.io (aFull Stack monitoring and App management web service) comes to the rescue. There highly active project PM2 [P(rocess) M(anager) 2] combine these cool features and is super easy to use.

The first, start a nodejs script

$ pm2 start app.js

The process is put in background, kept alive forever and monitored.

The second, managing the processes is pretty straightforward

$ pm2 list

pm2-list

$ pm2 stop <app_name|id|all>
$ pm2 restart <app_name|id|all>
$ pm2 delete <app_name|id|all>

The third, PM2 can generate and configure a startup script to keep PM2 and your processes alive at every server restart!

$ pm2 startup # auto-detect platform

(Execute the startup command only as the user to be running the PM2 daemon)

PM2 can also enables a built-in load balancing between multiple application to use all CPUs available in a server. Each HTTP/TCP/UDP request will be forwarded to one specific process at a time.

pm2 start app.js -i max  # Enable load-balancer and cluster features

PM2 is amazing when we have to manage several applications at once. It allows you to declare the behaviour of each application within a simple JSON file.

https://keymetrics.io/2015/05/06/microservices-architecture-applications-via-pm2/

This all is super smart.

No more fat JS frameworks

http://bitworking.org/news/2014/05/zero_framework_manifesto

In search of the perfect JavaScript framework my colleague and me we find out a new approach for building web apps and/or web services with tiny frameworks and libraries. For new projects we are using the following technology stack now:

Server-Side

  • NodeJS (NVM) – Server-Side Javascript’en
  • MongoDB – NoSQL Datastore
  • Express – Fast, unopinionated, minimalist web framework for Node.js
  • Node-restful (include mongoose) – A library for quickly providing a data api
  • PubSub – publication/subscription pattern in JS
  • socket.io – optionally for websocket communication
  • PM2 – Production process manager for Node.js. Perfectly fitted for microservices architecture.

Frontend

  • Babel – Use next generation JavaScript, today.
  • Mithril – minimalistic client-side MVC framework – a tool to organize code in a way that is easy to think about and to maintain
  • JSX – templates – XML-like syntax extension to ECMAScript
  • msx – JSX for Mithril: MSX
  • gulp – the streaming build system
  • gulp-msx – Precompile Mithril views which use JSX into JavaScript
  • lodash – utility library delivering consistency, modularity, performance, & extras
  • webpack – module/components bundler
  • youmightnotneedjquery

Getting Started

First I install NodeJS with the Node Version Manager and the MongoDB. Then I install globally the Express application generator. For example, the following creates an Express app named myapp in the current working directory:

express myapp
cd myapp

Then I also install node-restful by npm on the command line:

npm install node-restful --save
npm install

So I can start the basic RESTful API Express on http://localhost:3000/ now.

20th, March 2015: Solar Eclipse Experiment :)

IMG_0002

camera obscura

Colleague and me we instantly built a camera obscura experiment for the Solar Eclipse 2015.

« Older Entries