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

off white hoodie

I intended to create you one very small word to finally thank you so much as before with the remarkable advice you have contributed here. This has been remarkably open-handed with people like you to deliver without restraint just what a number of people might have supplied for an ebook to generate some bucks for their own end, precisely seeing that you might have tried it in the event you wanted. The principles as well served to be a easy way to recognize that most people have the identical eagerness similar to mine to understand a little more with regards to this matter. I think there are thousands of more pleasurable situations in the future for many who view your website.

coach outlet

I happen to be commenting to make you understand what a beneficial experience my wife's child went through visiting your blog. She figured out too many things, most notably how it is like to possess an excellent giving nature to get many others just learn several tricky subject areas. You undoubtedly surpassed visitors' expectations. Thank you for showing the good, healthy, explanatory not to mention cool guidance on that topic to Ethel.

vans

Thank you for your own efforts on this site. My niece really likes doing internet research and it is simple to grasp why. Many of us know all regarding the dynamic ways you deliver vital things via the web blog and inspire participation from the others about this theme then our child is in fact becoming educated a lot of things. Take advantage of the remaining portion of the new year. You're the one conducting a terrific job.

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.

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.

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.

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.

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.

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.

vans outlet

A lot of thanks for each of your effort on this website. My aunt really likes conducting investigations and it's easy to understand why. My spouse and i hear all of the lively mode you deliver useful strategies by means of the website and in addition foster response from other individuals on that area of interest so my simple princess is certainly learning so much. Have fun with the rest of the new year. You are doing a wonderful job.

balenciaga shoes

My spouse and i have been very satisfied Chris managed to round up his studies through the entire precious recommendations he made through your blog. It's not at all simplistic to simply continually be offering facts which often many others might have been selling. And we also acknowledge we've got the writer to be grateful to for this. The entire explanations you made, the simple blog menu, the relationships you make it easier to create - it's got many exceptional, and it's really helping our son and us reckon that the content is entertaining, and that's pretty indispensable. Thank you for all!

balenciaga sneakers

I simply had to appreciate you once more. I'm not certain the things I might have taken care of without the actual tips and hints shared by you relating to my area. This was the hard case for me personally, however , discovering a new specialized strategy you solved the issue forced me to cry with happiness. I am just grateful for this help and as well , sincerely hope you really know what a powerful job you are carrying out training other individuals via a site. I'm certain you haven't come across all of us.

air max 95

Thanks a lot for providing individuals with such a terrific possiblity to discover important secrets from this web site. It is always so awesome and also packed with fun for me and my office mates to search your website minimum thrice in a week to find out the newest guides you have. And indeed, we are usually astounded considering the incredible advice you give. Selected 3 ideas in this article are absolutely the most effective we've ever had.

curry 4

I'm just writing to let you know what a awesome discovery my cousin's daughter developed using yuor web blog. She learned too many issues, with the inclusion of what it's like to possess an awesome helping spirit to let men and women really easily thoroughly grasp specified impossible subject matter. You undoubtedly did more than her expected results. Many thanks for distributing the good, trustworthy, informative and also unique tips on this topic to Janet.

hermes birkin bag

My spouse and i ended up being absolutely relieved when Albert could round up his survey through the entire ideas he discovered out of the web site. It is now and again perplexing to just possibly be releasing thoughts which often the rest have been selling. So we take into account we have you to thank for that. The specific explanations you made, the easy site menu, the relationships you will make it possible to promote - it's got many incredible, and it is helping our son in addition to our family do think that topic is satisfying, which is unbelievably important. Thank you for all!

michael kors outlet

I and my guys ended up digesting the nice points located on your website and all of a sudden came up with a horrible suspicion I never expressed respect to the website owner for those tips. All the men happened to be certainly joyful to study all of them and already have unquestionably been loving them. Thank you for truly being really kind and also for making a choice on variety of wonderful ideas most people are really desirous to be informed on. My personal sincere regret for not expressing appreciation to earlier.

coach handbags

I am also writing to make you know of the incredible experience our girl developed reading the blog. She figured out lots of things, which include what it's like to have a very effective coaching spirit to make other people quite simply master chosen very confusing issues. You undoubtedly did more than people's expectations. I appreciate you for giving these warm and friendly, trustworthy, informative not to mention fun guidance on the topic to Jane.

golden goose sneakers

I would like to convey my admiration for your generosity giving support to people that should have help on in this question. Your special commitment to getting the message up and down was particularly insightful and have always encouraged most people just like me to realize their desired goals. Your amazing interesting publication means a lot a person like me and somewhat more to my fellow workers. Thanks a lot; from each one of us.

longchamp bags

I have to express my affection for your kind-heartedness for men who must have assistance with this important theme. Your personal commitment to getting the solution around ended up being quite helpful and have in every case helped folks much like me to get to their ambitions. Your amazing important hints and tips implies much a person like me and a whole lot more to my colleagues. Thank you; from everyone of us.

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!

kyrie irving shoes

I have to point out my passion for your kindness supporting women who must have assistance with the topic. Your very own dedication to getting the message up and down ended up being exceptionally insightful and have frequently empowered guys like me to achieve their targets. Your informative report signifies so much to me and somewhat more to my office workers. Warm regards; from all of us.

balenciaga

Thanks so much for providing individuals with an extraordinarily terrific possiblity to check tips from this site. It is often so fantastic and also jam-packed with fun for me personally and my office fellow workers to visit your web site at a minimum thrice in one week to see the latest guidance you will have. And of course, I am at all times impressed with all the sensational principles you give. Certain 4 facts on this page are in fact the most effective we have ever had.

yeezy shoes

I am glad for commenting to let you be aware of what a impressive encounter our daughter undergone reading the blog. She figured out too many details, not to mention what it is like to have a very effective coaching nature to get a number of people with ease have an understanding of a variety of extremely tough subject areas. You actually did more than visitors' expected results. Thank you for rendering these helpful, safe, explanatory and unique tips about this topic to Gloria.

longchamp handbags

I actually wanted to write down a simple remark in order to say thanks to you for all the fabulous steps you are placing on this site. My extensive internet investigation has finally been recognized with reputable facts to exchange with my close friends. I 'd assume that most of us website visitors actually are definitely lucky to dwell in a magnificent site with many awesome professionals with great hints. I feel very fortunate to have seen the website page and look forward to so many more fabulous moments reading here. Thanks again for all the details.

Pages

Add new comment