From Gentoo Wiki
(Redirected from NodeJS)
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

Node.js is a cross platform, open source, javascript server environment.

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, the goal is to 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

corepack Enable the experimental corepack package management tool
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
icu Enable ICU (Internationalization Components for Unicode) support, using dev-libs/icu
inspector Enable V8 inspector
lto Enable Link-Time Optimization (LTO) to optimize the build
npm Enable NPM package manager
pax-kernel Enable building under a PaX enabled kernel
snapshot Enable snapshot creation for faster startup
ssl Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
system-icu Use system dev-libs/icu instead of the bundled version
system-ssl Use system OpenSSL instead of the bundled one
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)


Node.js has a USE flag to include npm, the Node.js package manager. npm is necessary to install a Node.js application's dependencies, which are defined in a file named package.json. The USE can be disabled if npm is not necessary locally, or prefer to only install an alternative, for example, sys-apps/yarn.

Web application daemons with nginx and monit


Node.js typically responds directly to HTTP requests by running a server. Node.js works best with multiple instances running behind a load-balancing gateway, such as nginx.

Use app-admin/monit for spawning Node.js servers.

root #emerge --ask monit nginx nodejs

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;

Web application with openrc runscript

FILE /etc/init.d/nodejs-serverSample init.d file for a Node.js daemon
depend() {
	use net