Node.js installation and setup


Node.js is an open source platform for writing server-side web applications. It is based on an event-oriented and asynchronous programming with non-blocking I/O. The platform is designed to execute standalone web applications in JavaScript. It internally uses the Google V8 JavaScript engine to execute code.

Node.js can be integrated with Drupal 7, using the module Node.js integration. Let's try it in action, and at the end we will see whether node.js works correctly with this module.

First, you should install all the necessary packages for work with node.js and node.js itself:

sudo apt-get install build-essential git curl openssl libssl-dev

The most common method of installing node.js is to compile it from the source codes.

Note: you should replace v.0.8.x with the latest stable version from

mkdir -p ~/local/src

cd ~/local/src

git clone --branch v0.8.x git://

cd node



sudo make install

If there were no errors in the installation process, the node.js will be available for you. For example:

$ node

> console.log('Hello world');

Hello world

Our next step is to install the module node.js on Drupal. Then you should enter the directory with this module, using the following command:

$ cd path/to/your/nodejs/module/directory

Next the web developer should install all the required dependencies:

$ sudo npm install

$ sudo npm install

$ sudo npm install request

$ sudo npm install express

$ sudo npm install connect

After that you should enter node.js configuration page. You need to copy contents of "Suggested configuration" field, to create a sites/all/modules/nodejs/nodejs.config.js file and to paste the copied settings there.

Nodejs configuration

That is all, node.js platform is configured. To check whether it works you need to enable the "Nodejs Watchdog" module, which is included to the module’s Node.js integration package.

Not to type the same command a lot of times we can run ‘node server.js' in the background mode using forever package. Forever is able to manage the background processes: it can restart them after failure; redirect standard errors to the log files; and perform other useful functions. So you should install it on the server:

$ sudo npm install -g forever

Now you need to write 'forever start server.js' instead of 'node server.js'. To stop it you should execute 'forever stop server.js' function. You can also use 'forever list' to check what processes are running through forever.

To make node.js run automatically after system’s boot/reboot, you should create the init script in /etc/init.d/ directory.

In our case the script looks like this:

set -e
case "$1" in
        forever start $DAEMON
        forever stop $DAEMON 
      forever restart $DAEMON;;
    *) echo "Usage: /etc/init.d/node {start|stop|restart|force-reload}"
      exit 1
exit 0

You should save it in the file /etc/init.d/node and write the following commands in the terminal:

$ sudo update-rc.d node defaults 
$ sudo chmod +x /etc/init.d/node

That's it. Node.js setup is completed.

7 votes, Rating: 5

Read also


Often one can see such charges against Drupal: “It is impossible to build a high-load website using this framework”. We will refute this myth on...


One of the main issues after making decision to launch a website is development platform - CMS or custom coding? Let's elucidate Drupal framework advantages.


Very often a lot of developers face the issue of flexible materials sorting on the site. One of the solutions to solve this issue is Radioactivity module. Learn more about this tool.


We use "Git Flow" repository operations model quite often in our work. Let’s consider the scheme in detail.


Changes in Drupal 8 have also affected the process of creating your own widgets and formatters. The new Plugin API significantly simplifies this procedure.

Need a quote? Let's discuss the project

Are you looking for someone to help you with your Drupal Web Development needs? Let’s get in touch and discuss the requirements of your project. We would love to hear from you.

Join the people who have already subscribed!

Want to be aware of important and interesting things happening? We will inform you about new blog posts on Drupal development, design, QA testing and more, as well news about Drupal events.

No charge. Unsubscribe anytime