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

Spot on with this write-up, I really feel this web site needs
far more attention. I'll probably be returning to read through more,
thanks for the information!

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.

Add new comment | arxic Drupal

Hi to every one, for the reason that I am actually eager
of reading this blog's post to be updated on a regular basis.

It carries pleasant stuff.

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.

Add new comment | arxic Drupal

Heya i'm for the primary time here. I came across this board and I in finding It really helpful & it helped me out
much. I am hoping to give one thing back and aid others like
you aided me.

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

Aw, this was an incredibly nice post. Taking a few minutes and actual
effort to make a very good article… but what can I say… I put things off a whole lot and never manage to
get anything done.

Add new comment | arxic Drupal

My partner and I stumbled over here from a different web address and thought I may as
well check things out. I like what I see so now i am following you.

Look forward to looking over your web page repeatedly.

ferragamo belt

I definitely wanted to post a simple comment to thank you for those fabulous information you are giving on this site. My particularly long internet look up has finally been honored with reputable tips to go over with my best friends. I 'd repeat that most of us website visitors are rather fortunate to live in a magnificent site with many lovely individuals with very beneficial tricks. I feel pretty lucky to have come across your web site and look forward to tons of more thrilling times reading here. Thanks once more for all the details.

Add new comment | arxic Drupal

Hi, I do think this is an excellent web site. I stumbledupon it ;) I am going
to return yet again since I bookmarked it. Money and freedom is the best way to change, may you be rich
and continue to guide other people.

yeezy boost 350

I am glad for writing to make you know what a nice discovery my friend's daughter developed browsing your web site. She mastered some pieces, which include how it is like to possess an ideal coaching character to get the others effortlessly know specified advanced subject matter. You really exceeded our desires. I appreciate you for producing the essential, dependable, edifying as well as unique guidance on your topic to Jane.

Add new comment | arxic Drupal

Hi, I do think this is a great blog. I stumbledupon it ;)
I'm going to return once again since I book-marked it.
Money and freedom is the best way to change, may you be rich and continue to guide other people.

jordan 6

I'm also commenting to make you be aware of of the brilliant discovery my cousin's princess developed viewing your site. She even learned so many things, with the inclusion of what it's like to possess an excellent giving nature to make a number of people with no trouble know precisely various impossible subject matter. You really exceeded her desires. Many thanks for offering such essential, trusted, informative and in addition unique guidance on the topic to Sandra.

Add new comment | arxic Drupal

Hi there! This post could not be written any better!
Looking through this post reminds me of my previous roommate!
He continually kept preaching about this. I am going to forward this information to him.
Fairly certain he's going to have a great read. Many thanks for sharing!

curry shoes

Thanks so much for giving everyone an exceptionally splendid opportunity to read in detail from this site. It's usually so amazing and also full of a good time for me and my office peers to visit your website the equivalent of three times a week to learn the fresh stuff you will have. Of course, we are always satisfied with all the surprising things you serve. Selected 1 tips in this article are undoubtedly the simplest we have all had.

Add new comment | arxic Drupal

I am curious to find out what blog system you are working with?

I'm having some minor security issues with my latest site
and I'd like to find something more safe.
Do you have any suggestions?

curry 5

I am glad for commenting to let you know of the really good experience my friend's girl obtained browsing your blog. She figured out a lot of things, with the inclusion of what it's like to have a great helping mindset to have folks smoothly fully understand selected tricky subject matter. You really surpassed our own expected results. Thank you for churning out these informative, trustworthy, revealing as well as unique guidance on that topic to Emily.

Add new comment | arxic Drupal

Attractive section of content. I just stumbled upon your blog and in accession capital to assert
that I acquire in fact enjoyed account your blog posts.
Anyway I will be subscribing to your feeds and even I achievement you access consistently fast.

louboutin shoes uk

I am just commenting to make you know what a superb discovery my princess experienced viewing your web site. She even learned some pieces, with the inclusion of what it is like to have an excellent helping nature to have other individuals without difficulty know several multifaceted topics. You truly surpassed her desires. Thank you for coming up with those useful, dependable, informative and in addition cool thoughts on your topic to Janet.

Add new comment | arxic Drupal

Your style is really unique in comparison to
other folks I have read stuff from. Thank you for posting when you've got the opportunity, Guess
I'll just book mark this web site.

michael jordan shoes

Thank you for your entire effort on this site. My daughter delights in working on internet research and it's easy to understand why. We know all about the powerful tactic you produce effective things through your blog and even foster contribution from website visitors on the subject and my daughter is without a doubt being taught a whole lot. Enjoy the rest of the new year. Your doing a glorious job.

Add new comment | arxic Drupal

Right now it sounds like Movable Type is the top blogging platform out
there right now. (from what I've read) Is that what you are
using on your blog?

balenciaga

Needed to post you that little bit of word in order to say thanks a lot once again for all the nice tactics you've shown on this page. It was really particularly generous with you to provide without restraint all that a lot of people might have offered for sale as an ebook to earn some cash on their own, even more so since you could possibly have tried it if you ever wanted. Those solutions additionally acted to become good way to be aware that some people have the identical dream the same as my very own to learn a good deal more around this problem. I am sure there are many more pleasant times ahead for individuals who looked at your site.

Add new comment | arxic Drupal

Nice blog! Is your theme custom made or did you download it from
somewhere? A theme like yours with a few simple tweeks would really make
my blog stand out. Please let me know where you got your theme.
Cheers

yeezy shoes

Thank you for every one of your work on this blog. My daughter really loves getting into internet research and it's obvious why. We all know all relating to the lively ways you create powerful tricks on this blog and in addition boost participation from other people about this concern so our favorite daughter has always been discovering a whole lot. Have fun with the remaining portion of the new year. You're the one carrying out a powerful job.

westbrook shoes

I as well as my pals were found to be analyzing the best points located on your website and immediately I had a horrible suspicion I had not expressed respect to the website owner for those tips. These men are actually thrilled to read them and already have simply been tapping into them. Many thanks for genuinely simply considerate as well as for using some notable tips millions of individuals are really desperate to be informed on. My personal sincere regret for not expressing appreciation to earlier.

balenciaga

I simply needed to appreciate you all over again. I'm not certain the things that I would have accomplished in the absence of those solutions discussed by you relating to such theme. It previously was the daunting crisis in my view, however , coming across the expert fashion you handled that forced me to jump with happiness. I am thankful for your information and even pray you realize what a great job that you are undertaking educating some other people all through your web blog. I am sure you've never got to know all of us.

kate spade handbags

I must point out my admiration for your generosity giving support to men who require help on that topic. Your real dedication to passing the solution throughout had become extraordinarily important and has always empowered people like me to attain their endeavors. Your new interesting advice signifies a whole lot to me and further more to my peers. Thank you; from all of us.

Add new comment | arxic Drupal

You actually make it seem really easy together with your presentation but I in finding this matter
to be really something that I think I might never understand.
It seems too complex and extremely huge for me. I am taking a look forward for your next publish, I will try to get the grasp of it!

nike shox for men

Thank you so much for giving everyone an exceptionally pleasant opportunity to read from this website. It's usually very cool plus jam-packed with a lot of fun for me and my office peers to visit the blog more than three times per week to find out the latest guides you have got. And indeed, I am always pleased for the incredible solutions you serve. Some two facts in this posting are essentially the very best we have had.

off white nike

Thank you for your own work on this blog. Kim loves making time for investigation and it's really easy to understand why. All of us know all relating to the lively tactic you give precious tips and tricks via this web site and as well as recommend participation from some other people about this subject then our simple princess is undoubtedly understanding a lot of things. Take advantage of the rest of the year. Your carrying out a great job.

hermes belt

Thanks so much for giving everyone remarkably wonderful chance to discover important secrets from here. It really is so nice and packed with a great time for me and my office friends to visit your website more than thrice in one week to read through the fresh tips you have. And lastly, I am just certainly motivated with all the gorgeous ideas you serve. Some 2 ideas on this page are easily the best we have all had.

Add new comment | arxic Drupal

Link exchange is nothing else except it is only placing the other person's webpage link on your page at proper place and other person will
also do same in favor of you.

adidas superstar shoes

Thanks so much for giving everyone a very spectacular chance to read in detail from this web site. It's usually so pleasant plus packed with a great time for me and my office acquaintances to search the blog at a minimum three times in one week to find out the new secrets you have got. Not to mention, I'm usually amazed with all the exceptional methods you give. Selected 1 ideas on this page are indeed the simplest I have ever had.

Add new comment | arxic Drupal

I was suggested this website by my cousin. I'm not sure whether
this post is written by him as nobody else know such detailed about my trouble.
You're wonderful! Thanks!

air jordan

Thanks for every one of your effort on this website. Kim take interest in making time for research and it is easy to understand why. We all learn all about the lively form you make worthwhile strategies on this blog and as well cause contribution from other people on the concept so our own child is in fact understanding a great deal. Take pleasure in the rest of the year. You're the one performing a dazzling job.

Add new comment | arxic Drupal

Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
Any way I will be subscribing to your augment and even I achievement you access
consistently fast.

jordan shoes

My wife and i have been really relieved when John could carry out his basic research through the precious recommendations he made from your own weblog. It is now and again perplexing to simply always be offering tips which many people might have been making money from. And now we already know we've got the writer to give thanks to for this. All of the explanations you made, the straightforward web site navigation, the friendships you aid to foster - it's got everything powerful, and it is aiding our son in addition to our family reason why the idea is satisfying, and that's pretty mandatory. Many thanks for all the pieces!

Add new comment | arxic Drupal

naturally like your website however you need to take a look
at the spelling on several of your posts. Several of them are rife with spelling problems and I to find
it very bothersome to tell the truth then again I'll certainly
come again again.

Pages

Add new comment