From Gentoo Wiki
Jump to: navigation, search
This is a work in progress!

About Installation

This guide will walk through installing Node.js behind nginx and using Monit to keep Node instances alive. Since Node.js is a single-process application, we will launch multiple instances of the application and load balance using nginx.


USE flags

USE flags for net-libs/nodejs A JavaScript runtime built on Chrome's V8 JavaScript engine

inspector Enable V8 inspector
npm Enable NPM package manager
snapshot Enable snapshot creation for faster startup
systemtap Enable SystemTAP/DTrace tracing


root #emerge --ask monit nginx nodejs


Node.js has a USE flag to include npm, the Node.js package manager. You will need it to install a Node.js application's dependencies, which are defined in a file named package.json.

The current stable version of Node.js, 6.11.x, comes with npm 3.10.x.

If you need a newer version like npm 5.6.x, use Node.js 8.9.x (the next LTS release) or later. You can configure which version to pull in by setting keywords, e.g.:

FILE /etc/portage/package.keywords/nodejs

Also see Knowledge_Base:Accepting_a_keyword_for_a_single_package.

Configure Monit

FILE /etc/monit.d/my-appAuto restart NodeJS App
check process mysql with pidfile /var/run/my-app/
    start program = "/bin/bash -c 'rc-service mysql start'"
    stop program  = "/bin/bash -c 'rc-service mysql stop'"

Configure Nginx

FILE /etc/nginx/nginx.confNginx Config
http {
    upstream myapp1 {

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;