Drupal and Node JS on Ubuntu Localhost

Recently I was trying to get the Node.js integration module running on my localhost with drupal running under a sub-directory and running into a few issues. The main item being that the configuration generation tool in the Node.js integration module did not seem to work as expected. Here are the consolidated set of steps I took to eventually get the 'Broadcast Message' to actually work.

Install Node and NPM [node package manager]

I did follow the instructions on the Node.js integration documentation with one caveat, I installed node and npm separately as it errored with some strange dependency issues.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

I ended up having to install npm from source using the following (be patient, it might look like it has frozen, but it can take a few minutes to complete):

curl https://npmjs.org/install.sh | sudo sh

You can verify the npm installation by running npm -v.

Install the Node.js integration module into your drupal site

If you're using drush you can just run the following from your Drupal directory:

drush dl nodejs

Otherwise install and enable the Node.js integration module as any other Drupal module. You'll want to enable the following modules once installed:

  • Nodejs integration
  • Nodejs Config
  • Nodejs Notifications

Install required node modules with npm

sudo npm install
sudo npm install socket.io
sudo npm install request
sudo npm install express
sudo npm install connect

Generate your nodejs.config.js file

Go to admin/config/nodejs/config and provide the following:

  • Protocol used by Node.js server: HTTP
  • Node.js server host: localhost
  • Pages on which to enable node.js: *

Then got to admin/config/nodejs/js and provide the following:

  • Host: localhost
  • Port: 5000
  • Resource: /socket.io
  • Publish URL: publish
  • Service Key: [ANY RANDOM STRING]
  • Client write to channels: checked
  • Client write to clients: checked
  • Backend
    • Host: localhost
    • Port: 80
    • Auth Path: /drupal7/nodejs/message/If the front page of your local drupal site is http://localhost/drupal7
  • Debug: checked
  • Extensions: [LEAVE EMPTY]

Once you have all that entered, submit the form. When the page refreshes copy the 'Suggested Configuration' and paste it into a file named 'nodejs.config.js' in your nodejs module directory sites/all/modules/nodejs/nodejs.config.js

Here's a copy of the configuration file for my install:

backendSettings = {

Update your Drupal settings.php

Add the following to the bottom of your settings.php file:
$conf['nodejs_service_key'] = '[SERVICE KEY FROM ABOVE (ANY RANDOM STRING)]';

Start the Node server

From the command line, go to your nodejs module directory and run the following:
node server.js

You should see the following:

Started http server.
   info  - socket.io started

Test it out!

You'll want to open up two browser windows and place them side-by-side so you can see the node.js magic. In one window navigation to admin/config/nodejs/nodejs_notify/broadcast and in the other, go to any other page on the site. On the System-wide broadcast page, fill out the form and hit submit. You should see the message appear in your other browser window.


If you don't see the message, try some of the other setups found on the documentation page.


by Queen (not verified) on Fri, 02/07/2014 - 21:13

It is very useful. Thanks a lot for sharing.

by Meño (not verified) on Sun, 02/16/2014 - 14:00

Do you have any idea how to fix this? "Backend authentication url not found"

by Jaya (not verified) on Wed, 03/09/2016 - 02:03

You may want to check this link,

Make sure that you set the basePath variable to drupal-base-dir with respect to 'host' value.

Drupal and Node JS on Ubuntu Localhost | Gerrit Brands

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /homepages/29/d196880538/htdocs/drupal7/includes/common.inc:2681) in drupal_send_headers() (line 1212 of /homepages/29/d196880538/htdocs/drupal7/includes/bootstrap.inc).
  • PDOException: SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user 'dbo354826752'@'' for table 'watchdog': INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => cron [:db_insert_placeholder_2] => Attempting to re-run cron while it is already running. [:db_insert_placeholder_3] => a:0:{} [:db_insert_placeholder_4] => 4 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://gerritbrands.com/blog/drupal-and-node-js-ubuntu-localhost [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => 1521872520 ) in dblog_watchdog() (line 154 of /homepages/29/d196880538/htdocs/drupal7/modules/dblog/dblog.module).


The website encountered an unexpected error. Please try again later.