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 12

I truly wanted to type a brief note in order to express gratitude to you for all the nice suggestions you are giving at this website. My particularly long internet look up has now been compensated with extremely good knowledge to write about with my companions. I would state that that most of us site visitors are rather fortunate to exist in a really good community with many outstanding individuals with good techniques. I feel very grateful to have discovered your weblog and look forward to so many more enjoyable minutes reading here. Thank you again for everything.

balenciaga shoes

My spouse and i felt now delighted when Peter could complete his survey through your ideas he had from your own site. It is now and again perplexing just to possibly be giving for free methods many others have been making money from. And now we acknowledge we now have the blog owner to thank for that. Most of the explanations you've made, the easy web site navigation, the friendships you help to foster - it's all awesome, and it's really facilitating our son and our family consider that that topic is interesting, and that is very serious. Many thanks for all!

ralph lauren sale

I simply had to appreciate you yet again. I do not know what I would have achieved without those aspects revealed by you on that industry. It previously was the fearsome issue for me personally, nevertheless looking at the expert avenue you treated it took me to jump over joy. I'm just grateful for this assistance and pray you know what a powerful job you are getting into instructing the mediocre ones via your webblog. Most probably you've never come across all of us.

nike vapormax

My spouse and i have been quite joyful Edward could conclude his studies from the ideas he made using your weblog. It's not at all simplistic just to be releasing steps that many men and women might have been trying to sell. So we grasp we have got the blog owner to give thanks to for that. The entire explanations you've made, the easy site navigation, the friendships you can make it easier to create - it's everything spectacular, and it is letting our son in addition to the family consider that this matter is fun, and that's exceptionally vital. Many thanks for all the pieces!

coach handbags

Thanks a lot for providing individuals with remarkably memorable possiblity to read articles and blog posts from this site. It is always very terrific and also full of a good time for me and my office friends to search your site a minimum of three times in one week to read the latest items you have got. And definitely, we are always pleased concerning the breathtaking principles you serve. Certain 2 areas in this posting are certainly the most efficient I have had.

ferragamo belt

My husband and i felt absolutely peaceful when Emmanuel could do his homework through the entire precious recommendations he acquired out of the web site. It's not at all simplistic to simply happen to be making a gift of information and facts men and women could have been making money from. And we all realize we have the blog owner to give thanks to because of that. All the explanations you made, the straightforward site navigation, the friendships you give support to create - it is mostly overwhelming, and it is leading our son in addition to us imagine that this subject is exciting, and that's rather mandatory. Thank you for everything!

moncler

I wish to convey my appreciation for your kind-heartedness in support of men who absolutely need help with that matter. Your personal commitment to getting the solution along became extraordinarily helpful and have surely made ladies like me to attain their objectives. The valuable guidelines implies much to me and additionally to my office workers. Thanks a lot; from everyone of us.

michael kors outlet

I am writing to make you be aware of of the magnificent experience my wife's daughter experienced reading through your webblog. She mastered so many details, which include what it's like to have an awesome coaching spirit to have other people with ease have an understanding of specific specialized issues. You truly surpassed people's desires. Thank you for producing such invaluable, trustworthy, explanatory not to mention unique thoughts on this topic to Julie.

louboutin shoes

Thanks for all of your hard work on this website. Gloria loves engaging in internet research and it is simple to grasp why. My partner and i hear all relating to the dynamic manner you render helpful tricks through the web blog and in addition foster contribution from people about this concept then my girl is truly starting to learn a lot. Enjoy the rest of the new year. You have been conducting a glorious job.

off-white

My wife and i got very relieved Edward could carry out his basic research while using the precious recommendations he made from your very own weblog. It's not at all simplistic to just always be offering tips and tricks which often some others could have been selling. So we grasp we need the blog owner to appreciate because of that. These explanations you've made, the easy blog menu, the relationships you will make it possible to foster - it's all astounding, and it is facilitating our son in addition to our family do think that topic is enjoyable, which is certainly unbelievably essential. Thanks for the whole thing!

nike air max 270

I precisely desired to say thanks once more. I'm not certain the things I would have undertaken in the absence of the methods shared by you directly on that topic. It seemed to be a depressing difficulty for me personally, however , viewing a professional style you treated the issue took me to leap over fulfillment. I will be happy for this help and as well , pray you are aware of a powerful job you're carrying out educating the mediocre ones using your blog. Probably you've never encountered any of us.

jordan shoes

I must show some appreciation to the writer for rescuing me from this particular dilemma. As a result of researching through the search engines and seeing notions which are not beneficial, I assumed my entire life was done. Living devoid of the approaches to the difficulties you have sorted out by means of your short article is a crucial case, and the kind that could have negatively affected my career if I hadn't discovered your web page. Your main ability and kindness in touching the whole lot was important. I am not sure what I would have done if I hadn't encountered such a thing like this. It's possible to at this moment relish my future. Thanks very much for the reliable and results-oriented help. I will not hesitate to refer your blog post to any person who needs assistance about this matter.

paul george shoes

I simply had to thank you so much once more. I'm not certain the things that I would have done without those recommendations shared by you about that concern. It became a very difficult matter in my circumstances, but spending time with your well-written mode you processed the issue made me to jump for joy. Now i'm happier for your work and hope that you really know what a powerful job you happen to be accomplishing training others thru your web site. Most likely you have never encountered any of us.

golden goose

I simply wished to thank you very much once more. I'm not certain the things that I would have carried out without the entire information revealed by you concerning such area of interest. It became a real fearsome circumstance in my view, nevertheless discovering a new specialised fashion you treated the issue forced me to weep for delight. I am just happy for this work and thus trust you find out what an amazing job that you are providing instructing many others with the aid of your webblog. I know that you haven't met any of us.

jordans

I and also my buddies came reading the nice pointers found on your web page and then got a terrible feeling I had not thanked you for those tips. Those ladies were definitely as a result glad to read through them and now have in actuality been loving them. Appreciate your truly being very helpful as well as for using this form of good guides millions of individuals are really eager to be aware of. My honest regret for not saying thanks to earlier.

christian louboutin shoes

I intended to compose you one very small word to say thank you once again for all the amazing information you have documented above. It has been simply wonderfully generous with people like you giving publicly all some people would've offered as an ebook in making some money for themselves, precisely now that you might well have done it in case you decided. The ideas in addition worked to provide a fantastic way to realize that many people have a similar zeal similar to my very own to know more and more in regard to this matter. Certainly there are many more fun moments up front for individuals that examine your website.

michael kors

I would like to express thanks to this writer just for rescuing me from this particular instance. Because of looking out throughout the online world and getting solutions that were not beneficial, I believed my life was over. Existing devoid of the strategies to the issues you've sorted out by means of your entire blog post is a critical case, and ones which might have badly damaged my career if I had not encountered your web site. Your good competence and kindness in handling all the stuff was useful. I am not sure what I would have done if I hadn't come upon such a subject like this. It's possible to now look forward to my future. Thanks a lot so much for your expert and result oriented help. I will not be reluctant to endorse your site to any person who will need tips about this matter.

hermes belt

Aw, this was a really nice post. In idea I would like to put in writing like this moreover ?taking time and precise effort to make a very good article?however what can I say?I procrastinate alot and by no means appear to get something done.

lebron 17 shoes

There are certainly numerous details like that to take into consideration. That could be a nice point to convey up. I provide the ideas above as general inspiration however clearly there are questions like the one you deliver up the place the most important factor can be working in trustworthy good faith. I don?t know if best practices have emerged round issues like that, however I'm positive that your job is clearly identified as a fair game. Each boys and girls really feel the impression of just a moment抯 pleasure, for the rest of their lives.

nike vapormax

Youre so cool! I dont suppose Ive learn something like this before. So nice to find any individual with some authentic ideas on this subject. realy thanks for beginning this up. this website is one thing that's needed on the net, somebody with a bit originality. useful job for bringing something new to the web!

christian louboutin shoes

After research a few of the blog posts in your web site now, and I really like your manner of blogging. I bookmarked it to my bookmark website listing and will probably be checking back soon. Pls check out my website online as properly and let me know what you think.

golden goose

I used to be very pleased to seek out this net-site.I wished to thanks on your time for this wonderful read!! I definitely having fun with each little bit of it and I've you bookmarked to check out new stuff you blog post.

ultra boost 3.0

I precisely wished to thank you so much yet again. I do not know what I could possibly have carried out without these pointers discussed by you regarding this industry. It previously was an absolute scary crisis in my circumstances, nevertheless being able to see a new specialised tactic you treated the issue made me to jump for fulfillment. I am happier for your advice and even hope that you are aware of a powerful job you are getting into training other individuals all through your webpage. I know that you have never come across any of us.

moncler

I precisely had to thank you very much all over again. I am not sure the things I would've used without these concepts shown by you directly on such a subject. Completely was a difficult scenario in my view, however , being able to see the very well-written fashion you solved that forced me to weep for delight. I'm happy for the advice and even wish you recognize what a great job you're putting in training the others via your blog post. More than likely you've never encountered all of us.

michael kors handbags

I as well as my pals were checking the best guides from your website and quickly I had a horrible feeling I had not thanked the web blog owner for those secrets. Those boys ended up certainly passionate to read through them and have simply been making the most of them. I appreciate you for indeed being quite accommodating and for selecting some perfect themes most people are really desperate to be aware of. Our own sincere apologies for not saying thanks to earlier.

golden goose

I have to express my appreciation to you for rescuing me from this type of instance. Right after researching through the search engines and getting recommendations which are not productive, I assumed my life was gone. Living without the strategies to the problems you have solved by means of your entire short post is a crucial case, as well as those that could have badly affected my career if I hadn't come across the website. Your primary know-how and kindness in handling all the stuff was useful. I don't know what I would've done if I hadn't encountered such a solution like this. I am able to now look forward to my future. Thank you so much for the professional and sensible help. I won't be reluctant to propose your web blog to anybody who desires guidance on this matter.

converse outlet

I must convey my gratitude for your kindness in support of persons that have the need for guidance on this topic. Your real dedication to getting the message along ended up being pretty advantageous and have usually helped others just like me to arrive at their objectives. Your entire interesting instruction entails so much to me and a whole lot more to my fellow workers. Thanks a lot; from everyone of us.

kobe shoes

My spouse and i got now thrilled John could carry out his investigations from the precious recommendations he received in your web pages. It's not at all simplistic to just always be handing out secrets and techniques a number of people might have been selling. We take into account we've got the website owner to appreciate because of that. The specific explanations you made, the simple blog menu, the relationships your site assist to foster - it is all astonishing, and it is letting our son and our family reason why that situation is entertaining, which is certainly truly pressing. Thanks for all the pieces!

red bottom shoes

I would like to point out my passion for your generosity in support of individuals that actually need guidance on this one study. Your real dedication to getting the message along had been quite practical and has frequently made guys and women just like me to attain their dreams. Your new interesting guidelines can mean so much a person like me and still more to my office colleagues. Thanks a ton; from everyone of us.

jordans

I wish to show my appreciation to this writer for rescuing me from this particular scenario. Just after scouting through the internet and coming across advice which are not powerful, I assumed my life was done. Being alive without the presence of approaches to the issues you have fixed as a result of your entire article content is a crucial case, and the ones that might have adversely affected my entire career if I had not noticed your web site. Your own personal mastery and kindness in controlling all the details was priceless. I'm not sure what I would've done if I hadn't come across such a solution like this. I'm able to at this point relish my future. Thank you very much for your expert and effective guide. I won't hesitate to propose your web sites to anybody who requires recommendations about this topic.

converse shoes

I enjoy you because of your own efforts on this web page. My mom delights in doing investigations and it's really easy to see why. My spouse and i notice all of the powerful means you deliver very important tricks through your web blog and as well invigorate response from people on that article so my child is certainly being taught a lot. Take advantage of the remaining portion of the year. Your doing a remarkable job.

golden goose outlet

I wanted to write you the little note to give many thanks once again over the superb pointers you've discussed on this page. It was simply surprisingly open-handed of people like you to present easily what a lot of folks would've offered for sale for an electronic book to end up making some cash on their own, specifically now that you might well have tried it if you ever considered necessary. Those tips as well acted like a good way to be sure that the rest have the same passion like my very own to figure out very much more in respect of this problem. Certainly there are thousands of more enjoyable periods in the future for individuals who discover your website.

jordan 6

I am just commenting to let you know of the helpful discovery my friend's daughter gained visiting the blog. She even learned plenty of details, most notably how it is like to possess an excellent teaching style to have other folks easily thoroughly grasp some tricky subject areas. You actually did more than her desires. I appreciate you for showing these practical, trusted, edifying and even unique tips on the topic to Janet.

nike shoes for men

I have to express appreciation to this writer just for rescuing me from this type of matter. As a result of surfing through the the net and meeting thoughts which are not beneficial, I believed my entire life was well over. Existing without the strategies to the problems you've solved by way of the site is a serious case, as well as those which may have adversely affected my entire career if I hadn't come across your website. Your own mastery and kindness in touching every item was precious. I am not sure what I would have done if I hadn't come upon such a thing like this. I can also at this moment look forward to my future. Thanks for your time very much for the high quality and effective help. I won't be reluctant to endorse the sites to any individual who should have support on this subject matter.

Add new comment | arxic Drupal

great publish, very informative. I ponder why the
other specialists of this sector do not understand this.
You must continue your writing. I'm confident, you have a huge
readers' base already!

timberland outlet

I want to show my appreciation to the writer for bailing me out of this type of challenge. Because of looking out throughout the online world and seeing ideas which were not pleasant, I thought my life was gone. Being alive minus the solutions to the issues you've sorted out by means of the posting is a critical case, and ones that could have adversely damaged my career if I had not discovered your website. Your primary know-how and kindness in dealing with all the pieces was important. I am not sure what I would have done if I had not come upon such a step like this. I can also now look forward to my future. Thanks for your time so much for your impressive and sensible help. I won't be reluctant to endorse your web sites to any person who would like guidelines about this area.

nike sneakers

My wife and i ended up being quite happy Raymond could finish up his research through your ideas he discovered using your weblog. It is now and again perplexing to simply find yourself giving freely strategies that many men and women might have been selling. Therefore we grasp we have the writer to give thanks to for that. All of the explanations you've made, the easy website menu, the friendships you can help to engender - it's got all fabulous, and it is leading our son in addition to our family do think that topic is cool, which is certainly seriously fundamental. Thank you for everything!

Add new comment | arxic Drupal

Hi! I could have sworn I've been to your blog before but after looking at some of the articles I realized it's new to me.

Nonetheless, I'm certainly delighted I stumbled upon it and I'll
be bookmarking it and checking back often!

louboutin outlet

I precisely had to appreciate you yet again. I do not know what I might have sorted out in the absence of the entire suggestions shared by you over this subject matter. It became an absolute horrifying circumstance in my position, but being able to view your specialised technique you dealt with it made me to cry with delight. Now i'm happy for this work and in addition believe you recognize what a great job you are accomplishing educating many people all through a web site. Probably you have never met any of us.

Add new comment | arxic Drupal

I think this is one of the most significant info for me. And i am glad reading your article.
But want to remark on some general things, The site style is wonderful, the articles is really excellent :
D. Good job, cheers

off white jordan 1

I precisely wanted to thank you very much once more. I am not sure the things that I could possibly have done without the actual suggestions shared by you relating to such area. It absolutely was a frustrating situation for me, nevertheless taking a look at a skilled avenue you dealt with the issue made me to weep for contentment. I am happier for the information and in addition expect you recognize what a great job your are doing instructing men and women by way of your blog post. I am sure you've never encountered all of us.

Add new comment | arxic Drupal

Thank you for the auspicious writeup. It actually was once a enjoyment account it.
Look complicated to far introduced agreeable from you!
However, how can we keep up a correspondence?

supreme clothing

My spouse and i ended up being absolutely ecstatic that Raymond managed to carry out his research because of the ideas he made out of the blog. It's not at all simplistic just to continually be giving out steps that many a number of people may have been trying to sell. So we know we have got you to give thanks to for that. The main illustrations you have made, the straightforward blog navigation, the relationships your site aid to promote - it is many astounding, and it's facilitating our son and the family know that this content is entertaining, which is exceedingly pressing. Thank you for all!

Add new comment | arxic Drupal

Wow, amazing blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your website is great,
as well as the content!

golden goose

I intended to compose you one tiny remark so as to thank you so much as before about the spectacular suggestions you have documented on this page. It is certainly seriously open-handed with people like you to offer extensively what exactly most of us might have sold as an e-book to help make some dough for their own end, most importantly considering that you could have tried it in the event you desired. Those tricks in addition acted to become good way to be sure that many people have similar keenness much like my own to find out somewhat more in respect of this problem. I know there are some more enjoyable times in the future for folks who discover your site.

Pages

Add new comment