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

Add new comment | arxic Drupal

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!

Add new comment | arxic Drupal

Excellent post. I used to be checking constantly this weblog and I am inspired!

Very helpful information specifically the final
phase :) I deal with such information a lot.

I was seeking this particular info for a very long time. Thanks and best
of luck.

Add new comment | arxic Drupal

When I initially commented I appear to have clicked on the -Notify me when new
comments are added- checkbox and now whenever
a comment is added I get 4 emails with the exact same comment.
Perhaps there is an easy method you can remove me from
that service? Kudos!

converse shoes

I抦 impressed, I need to say. Actually not often do I encounter a weblog that抯 both educative and entertaining, and let me tell you, you've hit the nail on the head. Your concept is excellent; the problem is something that not enough persons are speaking intelligently about. I am very pleased that I stumbled across this in my seek for something referring to this.

adidas tubular

Spot on with this write-up, I actually assume this website wants rather more consideration. I抣l in all probability be again to learn much more, thanks for that info.

hogan outlet

The following time I read a blog, I hope that it doesnt disappoint me as a lot as this one. I mean, I know it was my option to learn, however I really thought youd have one thing fascinating to say. All I hear is a bunch of whining about one thing that you possibly can repair if you werent too busy searching for attention.

yeezy boost 500

I found your weblog site on google and test a couple of of your early posts. Continue to keep up the superb operate. I simply further up your RSS feed to my MSN News Reader. Looking for ahead to studying extra from you in a while!?

kyrie 5 spongebob

After examine a few of the blog posts in your website now, and I actually like your manner of blogging. I bookmarked it to my bookmark web site listing and shall be checking again soon. Pls try my website online as properly and let me know what you think.

kyrie shoes

I was very happy to find this internet-site.I wanted to thanks in your time for this excellent learn!! I definitely enjoying every little bit of it and I have you bookmarked to take a look at new stuff you weblog post.

hermes bag

There are some fascinating deadlines on this article however I don抰 know if I see all of them center to heart. There is some validity but I will take maintain opinion till I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as nicely

curry 4

I was more than happy to find this internet-site.I wanted to thanks on your time for this glorious learn!! I definitely enjoying every little little bit of it and I've you bookmarked to take a look at new stuff you weblog post.

hermes online

Aw, this was a very nice post. In idea I would like to put in writing like this moreover ?taking time and actual effort to make a very good article?but what can I say?I procrastinate alot and on no account seem to get one thing done.

golden goose

Can I simply say what a aid to search out someone who really knows what theyre speaking about on the internet. You undoubtedly know how you can bring a difficulty to gentle and make it important. More individuals need to learn this and understand this side of the story. I cant believe youre no more popular since you undoubtedly have the gift.

nike air max

When I initially commented I clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the same comment. Is there any approach you'll be able to remove me from that service? Thanks!

Add new comment | arxic Drupal

Thank you for every other informative website. Where else may just
I get that type of information written in such a perfect way?
I have a mission that I'm just now operating on, and I have been on the glance
out for such info.

Add new comment | arxic Drupal

You really make it seem so easy with your presentation but I find this matter to
be actually something that I think I would never understand.

It seems too complicated and extremely broad for me.
I am looking forward for your next post, I'll
try to get the hang of it!

nfl jerseys

An interesting dialogue is value comment. I think that it is best to write more on this subject, it might not be a taboo subject but generally individuals are not sufficient to speak on such topics. To the next. Cheers

off white

Can I simply say what a reduction to search out someone who really is aware of what theyre speaking about on the internet. You definitely know find out how to deliver a difficulty to light and make it important. Extra individuals must learn this and understand this aspect of the story. I cant believe youre not more in style since you positively have the gift.

nike air max

I抎 must examine with you here. Which is not something I normally do! I take pleasure in reading a publish that will make individuals think. Also, thanks for allowing me to remark!

converse shoes

I抎 need to verify with you here. Which isn't something I normally do! I get pleasure from studying a post that will make people think. Additionally, thanks for permitting me to comment!

supreme hoodie

I am typically to blogging and i really recognize your content. The article has really peaks my interest. I'm going to bookmark your website and keep checking for brand spanking new information.

golden goose outlet

Can I just say what a relief to search out somebody who actually knows what theyre talking about on the internet. You positively know the right way to bring a problem to gentle and make it important. Extra folks need to read this and perceive this side of the story. I cant consider youre not more widespread since you undoubtedly have the gift.

golden goose sneakers

That is the appropriate blog for anyone who wants to search out out about this topic. You understand a lot its nearly arduous to argue with you (not that I truly would want匟aHa). You definitely put a new spin on a subject thats been written about for years. Nice stuff, simply nice!

nike kyrie 5

Spot on with this write-up, I actually suppose this web site needs way more consideration. I抣l in all probability be once more to read rather more, thanks for that info.

jordan shoes

This website can be a stroll-by for all the data you wished about this and didn抰 know who to ask. Glimpse here, and also you抣l undoubtedly discover it.

curry shoes

An impressive share, I simply given this onto a colleague who was doing a bit analysis on this. And he in fact bought me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I really feel strongly about it and love studying extra on this topic. If doable, as you grow to be experience, would you mind updating your weblog with more particulars? It's highly useful for me. Large thumb up for this weblog submit!

balenciaga

An fascinating discussion is price comment. I believe that you should write extra on this matter, it might not be a taboo topic but usually individuals are not sufficient to speak on such topics. To the next. Cheers

cheap jordans

Youre so cool! I dont suppose Ive learn anything like this before. So good to find any individual with some unique ideas on this subject. realy thank you for starting this up. this website is one thing that's needed on the internet, someone with a bit of originality. useful job for bringing something new to the internet!

supreme clothing

I'm typically to blogging and i actually respect your content. The article has really peaks my interest. I'm going to bookmark your web site and keep checking for new information.

off white clothing

That is the fitting weblog for anyone who needs to seek out out about this topic. You notice a lot its almost exhausting to argue with you (not that I actually would want匟aHa). You positively put a new spin on a topic thats been written about for years. Great stuff, simply great!

curry 4

An attention-grabbing discussion is worth comment. I feel that it is best to write extra on this subject, it won't be a taboo topic however typically persons are not sufficient to talk on such topics. To the next. Cheers

golden goose

Hello! I just wish to give a huge thumbs up for the nice information you may have right here on this post. I can be coming again to your weblog for extra soon.

christian louboutin shoes

Can I simply say what a relief to seek out someone who truly is aware of what theyre speaking about on the internet. You positively know how you can bring a problem to mild and make it important. Extra individuals need to learn this and understand this facet of the story. I cant imagine youre no more well-liked because you definitely have the gift.

russell westbrook shoes

An interesting discussion is price comment. I feel that it's best to write more on this matter, it won't be a taboo topic however usually persons are not enough to talk on such topics. To the next. Cheers

golden goose

The following time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my option to learn, however I really thought youd have something fascinating to say. All I hear is a bunch of whining about something that you would repair when you werent too busy looking for attention.

jordan shoes

There are some interesting points in time in this article however I don抰 know if I see all of them center to heart. There's some validity but I'll take maintain opinion till I look into it further. Good article , thanks and we want more! Added to FeedBurner as nicely

off white clothing

An attention-grabbing dialogue is worth comment. I feel that it is best to write extra on this subject, it won't be a taboo topic but generally people are not enough to talk on such topics. To the next. Cheers

kate spade handbags

I抎 need to check with you here. Which isn't something I often do! I get pleasure from studying a post that may make folks think. Additionally, thanks for allowing me to comment!

nhl jerseys

A powerful share, I simply given this onto a colleague who was doing slightly analysis on this. And he the truth is bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If doable, as you turn out to be experience, would you thoughts updating your blog with extra details? It's highly helpful for me. Huge thumb up for this weblog submit!

balenciaga

Aw, this was a really nice post. In thought I wish to put in writing like this additionally ?taking time and precise effort to make an excellent article?however what can I say?I procrastinate alot and under no circumstances appear to get something done.

Pages

Add new comment