Installing and configuring Node.js on Ubuntu 12.04 for localhost and external multi-site Drupal installations

First, get the pre-requsite packages:

sudo apt-get install build-essential g++ libssl-dev curl git

Then, install the Python Software Properties package:

sudo apt-get install python-software-properties

Add the repository for node.js:

sudo apt-add-repository ppa:chris-lea/node.js

Run updates:

sudo apt-get update

Install Node.js and Node Package Manager:

sudo apt-get install nodejs npm

If you need or want to compile Node C++ modules, then install nodejs-dev:

sudo apt-get install nodejs-dev

Installing Sourcemint and Cloud9 is highly recommended if you want to make your own Node.js modules.

On Ubuntu and other Linux systems, make sure that the libxml2-dev package is installed, or the installation of Cloud9 will fail:

sudo apt-get install libxml2-dev

Ensure that Sourcemint is installed globally:

npm install -g sm

Then, install Cloud9 with Sourcemint:

sm clone --dev https://github.com/ajaxorg/cloud9/tree/master cloud9

Or, install Cloud9 with Sourcemint after git cloning Cloud9 (you must have git installed and properly configured on your system, but you probably should have git anyways *smiley face*):

Git clone Cloud9:

git clone https://github.com/ajaxorg/cloud9.git cloud9

Switch to the Cloud9 clone directory:

cd cloud9

Use Sourcemint install in the Cloud9 clone directory:

sm install

Assuming that you already have a Drupal multi-site installation on the machine, you need to create a site-specific copy of the Drupal nodejs module folder. Typically in a multi-site installation, all contributed modules (like nodejs) are placed in the sites/all/modules folder. But, since you need a separate instance of nodejs.config.js and server.js for each site, copy the nodejs modules folder into a new modules folder in site, at /sites/[YourSiteName]/modules/nodejs. This new modules folder will live next to the files folder for each site.

Switch into the site folder for the site that you want to use nodejs with:

cd /var/www/drupal/sites/[YourSiteName]

Make a new modules directory, assuming you don't have other site-specific modules for this site already:

mkdir modules

Get a copy of the nodejs module and unpack it in the site-specific modules folder. Drush is probably the easiest, assuming you have it set up, or you can also wget. Remember to check the nodejs module page to get the link to the latest stable version.

Switch into the site-specific modules directory:

cd modules

Download the nodejs module tarball:

wget http://ftp.drupal.org/files/projects/nodejs-7.x-1.0.tar.gz[/prettify]

Unpack the tarball:

tar -xvzf nodejs-7.x-1.0.tar.gz

And, delete the tarball:

sudo rm nodejs-7.x-1.0.tar.gz

Then, switch into the new nodejs folder for the site:

cd nodejs

Now it starts to get exciting. In the new nodejs module folder, you need to install npm (for each and every site). This must be done in the site-specific nodejs module folder at /sites/[YourSiteName]/modules/nodejs, because the packages.json file must be present. Make sure you are in the site-specific nodejs module folder, and:

npm install

In the module folder, you will see many files, but you are only really concerned with one, nodejs.config.js.example, at this time. Go ahead and make a copy of it for your actual usage:

cp nodejs.config.js.example nodejs.config.js

Edit the nodejs.config.js file to work for your site. At the time of writing, there were several extra lines in the example config file that seemed to be actually preventing server.js from starting, so make sure that you have everything exact, or you won't get any love from server.js.

sudo nano nodejs.config.js

The default example file, below the commented instructions, is currently filled with the following:

settings = {
  scheme: 'http',
  port: 8080,
  host: 'localhost',
  resource: '/socket.io',
  serviceKey: '',
  backend: {
    port: 80,
    host: 'drupalhost',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
   debug: false,
   sslKeyPath: '',
   sslCertPath: '',
   baseAuthPath: '/nodejs/',
   publishUrl: 'publish',
   kickUserUrl: 'user/kick/:uid',
   logoutUserUrl: 'user/logout/:authtoken',
   addUserToChannelUrl: 'user/channel/add/:channel/:uid',
   removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
   addChannelUrl: 'channel/add/:channel',
   removeChannelUrl: 'channel/remove/:channel',
   setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
   addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
   removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
   toggleDebugUrl: 'debug/toggle',
   contentTokenUrl: 'content/token',
   publishMessageToContentChannelUrl: 'content/token/message',
   extensions: [],
   clientsCanWriteToChannels: false,
   clientsCanWriteToClients: false,
   transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
   jsMinification: true,
   jsEtag: true,
   logLevel: 1
};

But, I was having a lot of trouble getting server.js started, and noticed that the module configuration utility did not include many of these lines. After removing the lines I had much greater success:

   kickUserUrl: 'user/kick/:uid',
   logoutUserUrl: 'user/logout/:authtoken',
   addUserToChannelUrl: 'user/channel/add/:channel/:uid',
   removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
   addChannelUrl: 'channel/add/:channel',
   removeChannelUrl: 'channel/remove/:channel',
   setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
   addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
   removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
   toggleDebugUrl: 'debug/toggle',
   contentTokenUrl: 'content/token',
   publishMessageToContentChannelUrl: 'content/token/message',

In the end, you want it to look like this, with the local network IP address of your server ('localhost' didn't seem to work for me, nor did the local loopback, 127.0.0.1):

settings = {
  scheme: 'http',
  port: 8181,
  host: '192.168.1.10',
  resource: '/socket.io',
  serviceKey: 'YourServiceKey',
  backend: {
    port: 80,
    host: 'yoursitename.com',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
   debug: false,
   sslKeyPath: '',
   sslCertPath: '',
   baseAuthPath: '/nodejs/',
   publishUrl: 'publish',
   extensions: [],
   clientsCanWriteToChannels: false,
   clientsCanWriteToClients: false,
   transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
   jsMinification: true,
   jsEtag: true,
   logLevel: 1
};

A couple of notes.

  • 'resource' is definitely '/socket.io'
  • 'baseAuthPath is definitely '/nodejs/'
  • publishUrl is definitely 'publish' (not 'nodejs/publish' as specified by the config utility)

If you use a service key, then add to your site's settings.php file:

/**
 * Node.js service key:
 *
 */
$conf['nodejs_service_key'] = 'YourServiceKey';

After getting your nodejs.config.js file edited, start the nodejs instance by running in the site-specific module folder:

node server.js

Bonus: DrupalChat integration:

Copy the server extension out of the DrupalChat module folder:

sudo cp /var/www/drupal/sites/all/modules/drupalchat/drupalchat_nodejs/drupalchat_nodejs.server.extension.js /var/www/drupal/sites/[YourSiteName]/modules/nodejs/drupalchat_nodejs.server.extension.js

Add the extension to the nodejs.config.js file:

extensions: ['drupalchat_nodejs.server.extension.js']

Drupal version: 
Modules: 
Audience: 

Comments

Hey there would you mind letting me know which hosting
company you're utilizing? I've loaded your blog in 3 completely different web browsers and I must say this blog loads
a lot faster then most. Can you suggest a good hosting provider at a
reasonable price? Many thanks, I appreciate it!

I've been suurfing online more than 2 hours today, yyet
I never found any interesting article like yours.
It's pretty worth enough for me. Personally, if all web ownerss and bloggers made good
ontent as you did, the net will be much more useful tha ever before.|
I couldn't refrain from commenting. Well written!|
I willl right away grab your rss as I can not in finding your
e-mail subscription link or e-newsletter service.
Do you've any? Please allow me recognize in oorder
tjat I may just subscribe. Thanks.|
It is the best time to make some plans for the future and it is time to be happy.
I've read this post and if I could I wish to suggest you some interesting thhings or advice.
Maybe you can write next aarticles referring to thi article.
I want to rsad even mkre things about it!|
It's perfect time tto make a few plans for the future and it is time to be happy.

I have learn this submit and if I may just I want to
counsel you soe interesting things or tips. Perhaps you could wrote next articles relating tto this article.
I want to read more things approximately it!|
I've bden surfing on-line greater than three hours as of late, but I byy noo means found any interesting article like yours.
It is beautiful price enough ffor me. In my view, if all web
owners and bloggers made just right content
material as you probably did, the wweb wull likely be
much more helpful than evsr before.|
Ahaa, its good conversation about ths paragraph here at this
web site, I have read all that, so at this tme me also commenting at
this place.|
I am sure this piece of writing has touched all the internet users, its really really pleasant
article on building up new website.|
Wow, this piece of writing is nice, myy younger sister
is analyzing thse kindds of things, therefore I am going to tell her.|
Saved as a favorite, I like your web site!|
Way cool! Some extremely valid points! I appreciate you writing this write-up and also the rest of the site is really good.|
Hi, I do think this is an excellent site. I stumbledupon it ;) I'm going to come back yet again since i have book marked
it. Money and freedom is the greatest way to change, may you be richh and continue to help others.|
Woah! I'm really enjoying the template/theme of this blog.
It's simple, yet effective. A lot of times it's challenging to get that "perfect balance" between user friendliness and appearance.
I must ssay that you've done a great job with this.

Also, the blog loads super quick for me on Internet explorer.
Exceptional Blog!|
Thhese are aactually great ideas in regarding blogging.

You hsve touched sopme pleasant points here. Any way keep up wrinting.|
I really like what you guys tend to be up too. This kind of clever
work and exposure! Keep up the excellent wworks guys I've incorporated yyou guys to
our blogroll.|
Hey! Someone in myy Myspace group shared this website with us
so I czme tto look it over. I'm definitely enjoying the information. I'm book-marking and will be tweeting this
to my followers! Terrific blog and wonderful design and style.|
Everyone loves what you guys are usually up too. This kind of
clever work and exposure! Keep up the fantawtic works guys I've
included you guys to my blogroll.|
Hello would youu mond sharing which blog platform you're using?

I'm looking tto start my own blog in the near future but
I'm having a tough time selecting between BlogEngine/Wordpress/B2evolution annd Drupal.
The reason I ask is because your design and style seems different then most bloggs and I'm looking
for something completely unique.
P.S My apologies for being off-topic but I had to ask!|
Hello would you mind letting mme know which webghost you're using?
I've loaded your blog in 3 different web browsers and I must saay this blog loads a lot faster then most.

Can you suggest a good web hosting progider at a reasonable
price? Thanks, I appreciate it!|
I loge it when individuals come together and share opinions.

Great website, keep it up!|
Thank yoou for the auspicious writeup. It in fact was a amusement account it.
Look advanced to more added agreeable ffrom you! By the way, how can we communicate?|
Hi there just wanted to give you a quick heads up.
The text in your content see tto be running off the screen in Ie.
I'm not sure if this is a format issue oor something too
do with internet browser compatibility but I thought I'd post to let you know.
The design look great though! Hope you get thhe issue fixed soon. Cheers|
Thhis is a topic which is near too mmy heart...

Best wishes! Exactly where are your contact details though?|
It's vety trouble-free to find out any matter on net as compared to textbooks, as I found this paragraph at this web page.|
Does your sife have a contact page? I'm having a tough time
locating iit but, I'd like to shoot you an email. I've got some recommendations for your blog
you might be interested in hearing. Either way, great site andd Iloiok forward to
seeiing iit improve over time.|
Hi! I've been reading your weblog for a while now and finally
got the courage to go ahead and give you a shout out from
Porter Tx! Just wanted to tell you keep up the good
work!|
Greetings from Carolina! I'm bored at work so I decided to browse your site on my iphone during
lunch break. I love the info you present
hedre and can't wait to take a look when I get home.

I'm amazed at how fast your blog loaded on my mobile
.. I'm not eeven using WIFI, just 3G .. Anyhow, good site!|
Its such as you learn my mind! Yoou appear to know so much approximately this, like you wrote
the guide in it or something. I believe that you could do with some p.c.
to powe the message home a bit, but other than that, that
is great blog. A great read. I will certainly be back.|
I visited various websites but the audio feature for audio
songs existing at this web site is actually marvelous.|
Hi, i read your blog occasionally and i own a similar one and i wass just wondering if you get a lot off
spwm remarks? If so how do youu protect against it, aany plugin or anything you can recommend?
I get so much lately it's driving me insane so any hslp is ver much appreciated.|
Greetings! Very helpful advice in this particular article!
It's the little changes that produce the most important changes.
Thanks a lot for sharing!|
I absolutely lovee your blog.. Very nice colors
& theme. Did you create thiis amazing site yourself? Please reply back as I'm hoping to create
my very owwn site and would like to learn where you got this from or exactly what the theme
is called. Cheers!|
Hellko there! This article couldn't be written much better!

Reading through this article reminds me of my previous roommate!
He continually kept preaching about this. I will send this post to him.
Fairly certain he will have a very good read.
Thanks for sharing!|
Incredible! This blog look just like my olld one!

It's on a totally different subject but itt has pretty much the same page
layout and design. Superb choice of colors!|
There's certainly a great deal to find out about this issue.
I like all of the points you have made.|
You've made some deccent points there. Ilooked on the web for more information about the issue and found most people will go along with your views on this website.|
Hi, I check your new stuff like every week. Your
story-telling style is witty, keep up the goid work!|
I just could nnot leeave your site prior to suggesting that Ireally loved the usual info an individual supply
in your visitors? Is gonna be again ceaseleessly to investigate cross-check neww posts|
I needed to thank you forr this great read!! I absolutely enjoyed every bit of it.
I've got you book-marked to check out new stuff you post…|
Hello, just wanted to say, I enjoyed this post.

It was helpful. Keep oon posting!|
Hello, I enjoy reading all of your article.
I wanted to write a little comment to support you.|
I always spent my hallf aan hour to read this web site's
content daily along with a cup of coffee.|
I always emailed this blog post page to aall my associates, for the
reason that iif like too read it after that my conttacts will too.|
My coder is trying to persuade me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been using Movable-type on numerous websiges
forr about a ydar and am anxious about switching to
another platform. I have heard fantastic things about blogengine.net.
Is there a waay I can import all my wordpress content into it?
Any help would bee really appreciated!|
Hi! I could have sworn I've been to this blog before but after browsing through a few
of thee artihles I realized it's new to me. Nonetheless,
I'm certainly delighted I discovered it and I'll be book-marking it and checking back often!|
Grea article! This is the type of info that are supposed to bbe shared around the internet.
Shame on Google for now not positioning this put up higher!
Come on oger and discuss with my web site .
Thanks =)|
Heyya i'm for the first time here. I came across this board and
I find It reakly useful & it helped me out a lot.
I hope to give something back and help others like you
aidxed me.|
Greetings, I do believe your web site might be having browser compafibility issues.

When I look at your website in Safari, it looks fine however when opening in Internet Explorer, it
has some overlapping issues. I merely wanted to give you a
quick heads up! Besides that, excellent blog!|
Someone necessarily lendd a hand to make severely posts I would state.
This is the very first time I frequented youyr website page and up to now?
I surprised with thee research you made to create
this particular put up incredible. Magnificent job!|
Heya i am for the primary time here. I came across this board and
I in finding It trulpy helpful & it helped me out a lot.
I'm hoping to provfide one thing again andd aid others like yyou aixed me.|
Good day! I just wish to give you a huge thumbs uup for the excellent information you've got right here on thjis post.
I will be returning tto your web site for more soon.|
I all the time used to read article in news papers but now as I am a user
oof web so from now I am usimg net for articles
or reviews, thanks to web.|
Your mode of telling evverything in this post iis
truly nice, every oone be able to simply bbe aware of it, Thanks a
lot.|
Hi there, I discovered your blog by means of Google wilst searching for a comparable topic, your
website got here up, it appears to be like great.
I've bookmarked it in my google bookmarks.
Hello there, simply become akert to your blog tthrough Google,
aand located that it's trupy informative. I am going to
watch out for brussels. I will be grateful if you
happen to proceed this in future. Many other peoplke will be benefited out of your writing.
Cheers!|
I'm curious to find out what blog platform you have been using?
I'm having some minor security issues with my latest website aand I would
ljke to find somethinjg more secure. Do you have any suggestions?|
I'm extremely impdessed with your writing skills and also with the layoout on your blog.
Is this a paid theme or did you customize it yourself?
Anyway keep up the excellent quality writing, it is rare tto see
a nice blog like this one thedse days.|
I'm really impressed along with your writing skills and
also with the format in your blog. Is that this a paid sujbject or did you customize
it yourself? Anyway stay up the excellent quality writing, it iss uncommon to peer a great weblog like this onee these days..|
Hi, Neat post. There is a problem along with your web site
in web explorer, might test this? IE still is the marketplace leader
aand a big element of folks will miss your magnificent writing because
of this problem.|
I am not sure wher you are getting your information, but great topic.
I nerds to spend some time learning much more or understanding more.
Thanks for great info I was looking for this information for my mission.|
Hi, i think that i saw you visied my site so i came to “return the favor”.I am attempting to find things to improve my web site!I suppose its ok to use
a few of yo\

wonderful post, very informative. I ponder why the opposite
experts of the sector tend not to realize this.
You must proceed your writing. I'm sure, you may have an excellent readers'
base already!

Write more, thats all I have to say. Literally, it seems as though you relied on the
video to make your point. You obviously know what youre talking
about, why throw away your intelligence on just posting videos to your blog when you could be giving us something informative to read?

Add new comment