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

jordan shoes

I enjoy you because of each of your efforts on this web site. My aunt take interest in getting into research and it's simple to grasp why. Most people learn all about the powerful tactic you create great tricks on the web site and as well attract participation from other people on that article and our simple princess is actually learning a whole lot. Have fun with the remaining portion of the new year. You have been conducting a stunning job.

Add new comment | arxic Drupal

It's perfect 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 want to suggest you some interesting things or suggestions.
Perhaps you can write next articles referring to this
article. I want to read even more things about it!

Add new comment | arxic Drupal

Everything is very open with a really clear description of the issues.

It was definitely informative. Your site is extremely helpful.

Many thanks for sharing!

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.

Add new comment | arxic Drupal

Hi there I am so thrilled I found your webpage, I really found you by mistake, while I was looking on Google for something
else, Regardless I am here now and would just like to
say cheers for a incredible post and a all round enjoyable blog (I also
love the theme/design), I don’t have time to read it all at the moment
but I have saved it and also included your RSS feeds, so when I have time I will be back to read
much more, Please do keep up the excellent b.

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.

Add new comment | arxic Drupal

I was very pleased to discover this page. I want to to thank you for ones time just for this fantastic read!!
I definitely liked every little bit of it and I have you saved as a favorite
to check out new information in your site.

Add new comment | arxic Drupal

I have been browsing online more than 3 hours lately, but I never found any attention-grabbing article like yours.
It's beautiful worth sufficient for me. In my view, if all
website owners and bloggers made excellent content as you
did, the web will probably be much more helpful than ever before.

adidas nmd r1

I truly wanted to send a quick note so as to say thanks to you for those superb tactics you are giving at this site. My prolonged internet investigation has now been recognized with brilliant knowledge to go over with my two friends. I would express that most of us website visitors are definitely lucky to live in a perfect community with many lovely professionals with great techniques. I feel really fortunate to have discovered your entire site and look forward to many more fabulous moments reading here. Thanks again for a lot of things.

timberland boots

I am glad for writing to make you know of the fabulous experience my cousin's girl enjoyed checking your web site. She figured out lots of issues, with the inclusion of what it is like to possess a marvelous giving nature to get men and women very easily completely grasp certain impossible subject matter. You truly exceeded our expected results. Many thanks for giving such warm and helpful, healthy, revealing and also easy guidance on that topic to Lizeth.

Add new comment | arxic Drupal

I’m not that much of a online reader to be honest but your sites really nice, keep
it up! I'll go ahead and bookmark your site to come back down the road.

Many thanks

michael kors handbags

I would like to express my appreciation to you just for rescuing me from such a circumstance. As a result of checking through the the web and seeing ways which are not powerful, I assumed my entire life was gone. Living minus the answers to the difficulties you've solved all through your guideline is a critical case, and those which might have adversely affected my career if I had not encountered your site. Your own capability and kindness in touching the whole lot was crucial. I am not sure what I would have done if I had not encountered such a subject like this. It's possible to at this time look ahead to my future. Thank you very much for this expert and results-oriented help. I won't be reluctant to endorse the website to any person who wants and needs tips about this area.

supreme hoodie

A lot of thanks for each of your efforts on this site. Betty takes pleasure in carrying out internet research and it is simple to grasp why. Almost all know all about the powerful mode you create important techniques on the website and even welcome participation from others on the issue and our own daughter is certainly discovering a lot. Enjoy the rest of the year. You're carrying out a great job.

Add new comment | arxic Drupal

I needed to thank you for this very good read!! I absolutely
enjoyed every bit of it. I have got you saved as a favorite to
look at new stuff you post…

nike air max 95

I precisely desired to thank you so much yet again. I do not know what I would've used in the absence of the type of pointers shared by you relating to my concern. It truly was an absolute traumatic difficulty for me personally, nevertheless being able to view the expert mode you dealt with the issue took me to weep with contentment. I will be happy for the help and then wish you find out what a great job your are carrying out instructing most people by way of your web site. Most likely you've never encountered any of us.

moncler

I precisely had to say thanks yet again. I'm not certain the things that I might have sorted out in the absence of the entire ideas provided by you over such situation. It previously was an absolute frightening matter in my view, nevertheless finding out a expert strategy you handled it forced me to leap with happiness. I am just grateful for the service and as well , wish you know what an amazing job you're doing training the others using your web site. I'm certain you have never come across any of us.

Add new comment | arxic Drupal

We are a group of volunteers and opening a new scheme in our community.

Your web site provided us with valuable information to work on. You've done
an impressive task and our whole neighborhood will likely be thankful to you.

moncler

I actually wanted to type a small note to be able to appreciate you for all of the stunning recommendations you are sharing at this website. My long internet search has finally been compensated with pleasant points to talk about with my contacts. I 'd claim that most of us visitors actually are really endowed to live in a decent network with so many awesome individuals with useful advice. I feel pretty happy to have come across the website and look forward to really more enjoyable times reading here. Thank you once more for everything.

yeezy shoes

I together with my pals ended up reading the nice ideas from the blog while quickly I had a horrible feeling I had not expressed respect to you for them. My women were consequently very interested to read all of them and have in effect definitely been taking pleasure in those things. We appreciate you really being considerably accommodating and then for finding certain useful subjects millions of individuals are really desirous to learn about. Our sincere regret for not expressing appreciation to you earlier.

ferragamo belts

I'm also writing to let you be aware of what a exceptional experience my cousin's child went through going through yuor web blog. She figured out some things, including what it's like to possess an excellent giving mood to let most people without hassle comprehend a number of tortuous matters. You really exceeded our desires. Thank you for producing the powerful, safe, explanatory not to mention cool thoughts on your topic to Sandra.

off white x jordan 1

I enjoy you because of all your valuable effort on this web site. Kate loves carrying out research and it is easy to understand why. All of us notice all relating to the dynamic mode you produce important techniques on your blog and therefore recommend participation from other individuals about this idea so our girl has been learning so much. Take advantage of the rest of the year. You are doing a splendid job.

nike air force

I needed to compose you a bit of note to finally give many thanks again over the fantastic knowledge you've shown on this website. This has been wonderfully open-handed with you to grant openly what exactly a number of people might have supplied for an ebook to earn some money for themselves, notably considering that you might well have tried it if you ever desired. Those principles in addition worked to become a easy way to recognize that other people online have a similar dreams just as my personal own to realize a whole lot more with regards to this condition. I'm sure there are many more enjoyable periods in the future for people who go through your blog post.

Add new comment | arxic Drupal

Spot on with this write-up, I absolutely think this site needs
a lot more attention. I'll probably be back again to read through more, thanks for the advice!

kate spade handbags

I not to mention my buddies ended up following the nice tips on your web blog while all of the sudden came up with a horrible suspicion I had not expressed respect to the blog owner for them. My men had been as a consequence glad to read through all of them and have now absolutely been having fun with those things. We appreciate you really being really helpful and then for getting this form of high-quality areas millions of individuals are really needing to be informed on. Our own honest apologies for not saying thanks to earlier.

Add new comment | arxic Drupal

Thank you for some other fantastic post. The place else may just
anyone get that type of info in such an ideal method of
writing? I have a presentation subsequent week,
and I'm at the search for such information.

kobe shoes

I am commenting to make you understand what a nice experience my cousin's girl went through studying your web site. She mastered a wide variety of details, including how it is like to have an excellent helping heart to let the mediocre ones quite simply thoroughly grasp chosen impossible things. You undoubtedly surpassed our desires. Thank you for delivering such necessary, safe, edifying and even cool tips on the topic to Tanya.

vans outlet

I needed to write you this bit of observation to give thanks again for your extraordinary suggestions you have documented on this page. It's seriously generous of people like you to provide extensively all a few people could possibly have made available as an e book to help with making some bucks on their own, even more so considering the fact that you could have done it in case you considered necessary. Those smart ideas additionally served to be a fantastic way to be certain that other people online have the same keenness really like my own to figure out a lot more regarding this condition. Certainly there are thousands of more pleasurable situations ahead for many who read through your website.

Add new comment | arxic Drupal

I was wondering if you ever thought of changing the structure of your blog?
Its very well written; I love what youve got to say. But maybe you could a little more in the way of content
so people could connect with it better. Youve
got an awful lot of text for only having 1 or two images.

Maybe you could space it out better?

michael kors outlet

I would like to express my thanks to this writer for rescuing me from this challenge. Because of browsing throughout the world-wide-web and seeing views that were not productive, I believed my entire life was well over. Existing without the presence of strategies to the problems you have fixed by way of your guide is a crucial case, as well as the ones which might have adversely damaged my entire career if I had not discovered your blog. Your own skills and kindness in touching everything was useful. I don't know what I would've done if I had not encountered such a subject like this. I can at this time relish my future. Thanks a lot so much for the reliable and result oriented help. I won't hesitate to refer the blog to any individual who wants and needs guidelines about this problem.

Add new comment | arxic Drupal

Simply desire to say your article is as surprising.
The clearness in your post is just excellent and i could assume you're an expert on this subject.

Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post.
Thanks a million and please carry on the rewarding work.

jordan shoes

I not to mention my friends appeared to be going through the nice advice on your site then at once got an awful feeling I never thanked the blog owner for those techniques. These people were definitely for that reason excited to learn them and now have in truth been taking advantage of them. Thanks for simply being really accommodating as well as for considering this form of really good subject matter most people are really desperate to know about. My very own honest apologies for not expressing appreciation to you earlier.

golden goose outlet

My spouse and i got so fulfilled when Raymond could finish up his basic research using the precious recommendations he gained using your web pages. It's not at all simplistic to simply find yourself releasing hints that many others might have been trying to sell. We really recognize we now have the website owner to give thanks to because of that. The illustrations you have made, the easy web site navigation, the friendships your site aid to engender - it's everything terrific, and it is assisting our son and us believe that this article is pleasurable, which is certainly rather indispensable. Thanks for the whole lot!

Add new comment | arxic Drupal

Hey there! I know this is kind of off topic but I was
wondering if you knew where I could locate a captcha plugin for my comment form?
I'm using the same blog platform as yours and I'm having trouble finding one?
Thanks a lot!

kobe 9

I wanted to write you this little word to thank you yet again about the wonderful techniques you've contributed on this site. It has been really wonderfully generous with you giving openly all numerous people would've made available for an ebook to get some dough on their own, certainly considering that you could have tried it in the event you wanted. Those tactics additionally served to become a great way to fully grasp that some people have similar keenness like mine to know much more in regard to this issue. I know there are thousands of more fun occasions ahead for folks who scan your blog post.

Pages

Add new comment