Installing and configuring Node.js on Ubuntu 12.04 for localhost and external multi-site Drupal installations

First, get the pre-requsite packages:

sudo apt-get install build-essential g++ libssl-dev curl git

Then, install the Python Software Properties package:

sudo apt-get install python-software-properties

Add the repository for node.js:

sudo apt-add-repository ppa:chris-lea/node.js

Run updates:

sudo apt-get update

Install Node.js and Node Package Manager:

sudo apt-get install nodejs npm

If you need or want to compile Node C++ modules, then install nodejs-dev:

sudo apt-get install nodejs-dev

Installing Sourcemint and Cloud9 is highly recommended if you want to make your own Node.js modules.

On Ubuntu and other Linux systems, make sure that the libxml2-dev package is installed, or the installation of Cloud9 will fail:

sudo apt-get install libxml2-dev

Ensure that Sourcemint is installed globally:

npm install -g sm

Then, install Cloud9 with Sourcemint:

sm clone --dev https://github.com/ajaxorg/cloud9/tree/master cloud9

Or, install Cloud9 with Sourcemint after git cloning Cloud9 (you must have git installed and properly configured on your system, but you probably should have git anyways *smiley face*):

Git clone Cloud9:

git clone https://github.com/ajaxorg/cloud9.git cloud9

Switch to the Cloud9 clone directory:

cd cloud9

Use Sourcemint install in the Cloud9 clone directory:

sm install

Assuming that you already have a Drupal multi-site installation on the machine, you need to create a site-specific copy of the Drupal nodejs module folder. Typically in a multi-site installation, all contributed modules (like nodejs) are placed in the sites/all/modules folder. But, since you need a separate instance of nodejs.config.js and server.js for each site, copy the nodejs modules folder into a new modules folder in site, at /sites/[YourSiteName]/modules/nodejs. This new modules folder will live next to the files folder for each site.

Switch into the site folder for the site that you want to use nodejs with:

cd /var/www/drupal/sites/[YourSiteName]

Make a new modules directory, assuming you don't have other site-specific modules for this site already:

mkdir modules

Get a copy of the nodejs module and unpack it in the site-specific modules folder. Drush is probably the easiest, assuming you have it set up, or you can also wget. Remember to check the nodejs module page to get the link to the latest stable version.

Switch into the site-specific modules directory:

cd modules

Download the nodejs module tarball:

wget http://ftp.drupal.org/files/projects/nodejs-7.x-1.0.tar.gz[/prettify]

Unpack the tarball:

tar -xvzf nodejs-7.x-1.0.tar.gz

And, delete the tarball:

sudo rm nodejs-7.x-1.0.tar.gz

Then, switch into the new nodejs folder for the site:

cd nodejs

Now it starts to get exciting. In the new nodejs module folder, you need to install npm (for each and every site). This must be done in the site-specific nodejs module folder at /sites/[YourSiteName]/modules/nodejs, because the packages.json file must be present. Make sure you are in the site-specific nodejs module folder, and:

npm install

In the module folder, you will see many files, but you are only really concerned with one, nodejs.config.js.example, at this time. Go ahead and make a copy of it for your actual usage:

cp nodejs.config.js.example nodejs.config.js

Edit the nodejs.config.js file to work for your site. At the time of writing, there were several extra lines in the example config file that seemed to be actually preventing server.js from starting, so make sure that you have everything exact, or you won't get any love from server.js.

sudo nano nodejs.config.js

The default example file, below the commented instructions, is currently filled with the following:

settings = {
  scheme: 'http',
  port: 8080,
  host: 'localhost',
  resource: '/socket.io',
  serviceKey: '',
  backend: {
    port: 80,
    host: 'drupalhost',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
   debug: false,
   sslKeyPath: '',
   sslCertPath: '',
   baseAuthPath: '/nodejs/',
   publishUrl: 'publish',
   kickUserUrl: 'user/kick/:uid',
   logoutUserUrl: 'user/logout/:authtoken',
   addUserToChannelUrl: 'user/channel/add/:channel/:uid',
   removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
   addChannelUrl: 'channel/add/:channel',
   removeChannelUrl: 'channel/remove/:channel',
   setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
   addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
   removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
   toggleDebugUrl: 'debug/toggle',
   contentTokenUrl: 'content/token',
   publishMessageToContentChannelUrl: 'content/token/message',
   extensions: [],
   clientsCanWriteToChannels: false,
   clientsCanWriteToClients: false,
   transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
   jsMinification: true,
   jsEtag: true,
   logLevel: 1
};

But, I was having a lot of trouble getting server.js started, and noticed that the module configuration utility did not include many of these lines. After removing the lines I had much greater success:

   kickUserUrl: 'user/kick/:uid',
   logoutUserUrl: 'user/logout/:authtoken',
   addUserToChannelUrl: 'user/channel/add/:channel/:uid',
   removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
   addChannelUrl: 'channel/add/:channel',
   removeChannelUrl: 'channel/remove/:channel',
   setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
   addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
   removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
   toggleDebugUrl: 'debug/toggle',
   contentTokenUrl: 'content/token',
   publishMessageToContentChannelUrl: 'content/token/message',

In the end, you want it to look like this, with the local network IP address of your server ('localhost' didn't seem to work for me, nor did the local loopback, 127.0.0.1):

settings = {
  scheme: 'http',
  port: 8181,
  host: '192.168.1.10',
  resource: '/socket.io',
  serviceKey: 'YourServiceKey',
  backend: {
    port: 80,
    host: 'yoursitename.com',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
   debug: false,
   sslKeyPath: '',
   sslCertPath: '',
   baseAuthPath: '/nodejs/',
   publishUrl: 'publish',
   extensions: [],
   clientsCanWriteToChannels: false,
   clientsCanWriteToClients: false,
   transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
   jsMinification: true,
   jsEtag: true,
   logLevel: 1
};

A couple of notes.

  • 'resource' is definitely '/socket.io'
  • 'baseAuthPath is definitely '/nodejs/'
  • publishUrl is definitely 'publish' (not 'nodejs/publish' as specified by the config utility)

If you use a service key, then add to your site's settings.php file:

/**
 * Node.js service key:
 *
 */
$conf['nodejs_service_key'] = 'YourServiceKey';

After getting your nodejs.config.js file edited, start the nodejs instance by running in the site-specific module folder:

node server.js

Bonus: DrupalChat integration:

Copy the server extension out of the DrupalChat module folder:

sudo cp /var/www/drupal/sites/all/modules/drupalchat/drupalchat_nodejs/drupalchat_nodejs.server.extension.js /var/www/drupal/sites/[YourSiteName]/modules/nodejs/drupalchat_nodejs.server.extension.js

Add the extension to the nodejs.config.js file:

extensions: ['drupalchat_nodejs.server.extension.js']

Drupal version: 
Modules: 
Audience: 

Comments

Add new comment | arxic Drupal

Hey there would you mind letting me know which hosting
company you're utilizing? I've loaded your blog in 3 completely different web browsers and I must say this blog loads
a lot faster then most. Can you suggest a good hosting provider at a
reasonable price? Many thanks, I appreciate it!

Add new comment | arxic Drupal

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

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

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

Add new comment | arxic Drupal

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

converse shoes

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

Add new comment | arxic Drupal

With havin so much content and articles do you ever run into any issues of plagorism or copyright infringement?
My blog has a lot of completely unique content I've either
written myself or outsourced but it seems a lot of it is popping
it up all over the internet without my authorization.
Do you know any solutions to help protect against content from
being stolen? I'd definitely appreciate it.

adidas tubular

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

Add new comment | arxic Drupal

First of all I want to say great blog! I had a quick question in which I'd like
to ask if you don't mind. I was interested to find out how you
center yourself and clear your head prior to writing. I have had difficulty clearing my thoughts in getting my ideas out.
I do take pleasure in writing but it just seems like the first 10 to 15 minutes are lost just trying to figure out how to begin. Any ideas or hints?
Thanks!

hogan outlet

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

yeezy boost 500

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

Add new comment | arxic Drupal

Everything is very open with a precise clarification of the issues.
It was definitely informative. Your website is very useful.
Many thanks for sharing!

kyrie 5 spongebob

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

Add new comment | arxic Drupal

That is a really good tip particularly to those fresh to the blogosphere.
Brief but very precise info… Appreciate your sharing this one.
A must read article!

kyrie shoes

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

Add new comment | arxic Drupal

This is the right website for anyone who really wants to find out about
this topic. You know a whole lot its almost tough
to argue with you (not that I really will need to…HaHa).
You definitely put a fresh spin on a topic that's been discussed for decades.
Excellent stuff, just wonderful!

hermes bag

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

Add new comment | arxic Drupal

This is really attention-grabbing, You are an excessively professional blogger.

I've joined your feed and sit up for seeking extra
of your magnificent post. Additionally, I've shared your web site in my social networks

longchamp handbags

I truly wanted to write down a small comment in order to say thanks to you for the magnificent ways you are sharing at this site. My long internet investigation has at the end of the day been rewarded with wonderful concept to write about with my visitors. I 'd point out that most of us website visitors actually are definitely fortunate to dwell in a great site with so many awesome professionals with useful suggestions. I feel truly grateful to have seen your entire web page and look forward to so many more fabulous times reading here. Thank you once again for everything.

Add new comment | arxic Drupal

This is the right webpage for everyone who would like to find
out about this topic. You understand so much its almost tough
to argue with you (not that I personally will need to…HaHa).

You definitely put a new spin on a topic which has been discussed for
decades. Excellent stuff, just great!

louboutin

I want to express my appreciation for your generosity in support of those people who actually need assistance with in this theme. Your real dedication to getting the message all through appeared to be really productive and has truly enabled somebody much like me to attain their targets. The invaluable guidelines means much a person like me and much more to my fellow workers. Thanks a ton; from all of us.

Add new comment | arxic Drupal

Magnificent goods from you, man. I have understand your
stuff previous to and you are just extremely fantastic. I actually like what you've acquired here, certainly like
what you're stating and the way in which you say it. You make it enjoyable and you still care for to keep it wise.
I cant wait to read much more from you. This is really a great website.

hermes

I intended to put you one bit of word to be able to thank you very much as before relating to the wonderful ideas you have shown here. It was seriously open-handed of people like you to make without restraint what many of us would have sold for an e-book to get some cash for themselves, specifically since you could possibly have done it in the event you decided. Those advice as well acted to provide a easy way to recognize that other individuals have a similar dream much like my own to know the truth somewhat more with regards to this condition. I know there are thousands of more pleasurable moments in the future for folks who examine your blog post.

Add new comment | arxic Drupal

Hello! I just wanted to ask if you ever have any issues with
hackers? My last blog (wordpress) was hacked
and I ended up losing months of hard work due to no
data backup. Do you have any solutions to protect against
hackers?

jordan shoes

I must show my gratitude for your kindness supporting visitors who need help with this particular situation. Your very own commitment to passing the solution all around appeared to be surprisingly practical and have constantly made somebody like me to get to their endeavors. Your insightful help can mean a whole lot a person like me and especially to my colleagues. Warm regards; from each one of us.

Add new comment | arxic Drupal

My brother suggested I would possibly like this
blog. He used to be totally right. This post truly made my day.
You can not imagine simply how a lot time I had spent for this
information! Thanks!

calvin klein underwear

A lot of thanks for each of your work on this web page. Kim really loves engaging in investigations and it is simple to grasp why. My spouse and i know all about the compelling form you offer effective information through the website and even inspire contribution from the others on the theme and my princess is actually understanding a lot. Enjoy the remaining portion of the new year. Your performing a glorious job.

goyard

I have to show my appreciation for your generosity supporting visitors who require guidance on this particular content. Your real dedication to getting the solution along has been pretty beneficial and have continually encouraged professionals like me to get to their objectives. Your amazing warm and friendly guide means much to me and far more to my fellow workers. Warm regards; from each one of us.

Add new comment | arxic Drupal

For hottest information you have to pay a quick visit world wide web and
on the web I found this web page as a best website for hottest updates.

hermes belts

I definitely wanted to write down a comment in order to say thanks to you for all of the marvelous steps you are placing at this site. My incredibly long internet lookup has finally been recognized with brilliant facts and techniques to share with my visitors. I would admit that most of us website visitors are very much endowed to be in a useful network with many outstanding individuals with interesting solutions. I feel very much fortunate to have encountered the web site and look forward to plenty of more enjoyable moments reading here. Thanks once again for all the details.

Add new comment | arxic Drupal

I have to thank you for the efforts you have put in writing this blog.
I am hoping to check out the same high-grade content from you later on as well.
In fact, your creative writing abilities has inspired me to get my own blog now ;)

coach outlet

My wife and i ended up being joyful when Louis managed to finish up his investigation from your ideas he acquired from your own site. It is now and again perplexing to simply continually be giving away helpful tips which often people could have been selling. And we all discover we now have the writer to give thanks to because of that. The most important explanations you made, the straightforward website navigation, the relationships you will aid to engender - it is everything excellent, and it is helping our son and the family do think the idea is satisfying, and that's extraordinarily vital. Thank you for the whole thing!

air jordans

Thank you a lot for providing individuals with an extraordinarily marvellous chance to read articles and blog posts from this web site. It really is very brilliant and full of a good time for me and my office fellow workers to visit your website the equivalent of three times every week to study the newest secrets you will have. And indeed, I'm also certainly amazed for the wonderful tricks you serve. Certain two areas in this article are ultimately the most effective I have had.

Add new comment | arxic Drupal

When someone writes an post he/she retains the thought of a user in his/her brain that how a user can know
it. Therefore that's why this piece of writing is
great. Thanks!

balenciaga triple s

I wanted to send you a very small remark to thank you so much once again on your striking advice you have featured here. This is shockingly generous with you to present openly what exactly a lot of people would've marketed as an e book to make some money on their own, specifically now that you could have tried it in the event you desired. Those techniques also worked as a easy way to realize that the rest have a similar zeal similar to my very own to know more and more around this issue. I know there are lots of more pleasurable sessions in the future for many who go through your site.

kobe 9

Needed to draft you this very small word so as to say thanks the moment again for your extraordinary information you have contributed above. It is simply particularly open-handed of you to allow publicly all that numerous people could have advertised for an e-book to earn some profit for their own end, specifically now that you might well have tried it in the event you wanted. The tricks also served as the great way to be sure that most people have similar eagerness really like my very own to know the truth more and more on the subject of this matter. I think there are many more pleasant times ahead for many who take a look at your site.

Add new comment | arxic Drupal

I am extremely inspired with your writing abilities as well as with the structure for your weblog.
Is this a paid subject or did you customize it yourself?
Anyway stay up the excellent high quality writing, it's rare to
look a nice weblog like this one today..

air jordan

Needed to send you this little bit of word to thank you over again with your extraordinary pointers you've featured at this time. It has been quite shockingly open-handed of you to provide openly all many people could possibly have sold for an e-book to earn some cash for their own end, specifically considering the fact that you might well have done it if you ever decided. The guidelines also worked to become a good way to realize that most people have the same desire really like my personal own to realize a great deal more on the topic of this problem. I am sure there are lots of more pleasant moments ahead for individuals that start reading your blog.

Add new comment | arxic Drupal

I always used to study article in news papers but now as I am a user of internet therefore from now I am
using net for articles or reviews, thanks to web.

cheap jordans

I in addition to my pals appeared to be reading through the excellent tips on your website and so suddenly came up with a horrible feeling I never expressed respect to the web site owner for those tips. The women were definitely for this reason happy to see them and have now actually been making the most of these things. Thanks for truly being well helpful and also for finding some really good resources millions of individuals are really eager to discover. My personal sincere apologies for not saying thanks to you sooner.

louboutin

I and my friends were taking note of the good key points found on your web page while suddenly I got a horrible suspicion I had not thanked the web site owner for those tips. All of the people happened to be very interested to see all of them and have now honestly been enjoying them. We appreciate you genuinely considerably accommodating as well as for obtaining these kinds of superb subject areas millions of individuals are really desperate to know about. Our sincere apologies for not expressing appreciation to sooner.

off white

I must express some thanks to you just for bailing me out of such a setting. As a result of looking throughout the the net and finding techniques which were not beneficial, I figured my life was done. Being alive devoid of the answers to the difficulties you have solved by means of this short article is a critical case, as well as those which may have in a negative way damaged my career if I hadn't noticed your blog. Your main natural talent and kindness in handling every part was invaluable. I'm not sure what I would've done if I hadn't encountered such a subject like this. I can also now look forward to my future. Thank you very much for the specialized and result oriented help. I will not hesitate to refer your blog post to any individual who needs care on this area.

Add new comment | arxic Drupal

Hi there, I found your website by way of Google even as searching for a comparable topic,
your site got here up, it looks good. I've bookmarked it in my
google bookmarks.
Hi there, simply changed into aware of your weblog through Google,
and found that it's really informative. I'm
going to be careful for brussels. I'll be grateful when you continue
this in future. Lots of folks can be benefited from your writing.
Cheers!

nike shox for women

Thanks so much for giving everyone an extremely marvellous chance to read from this website. It is usually so lovely and also stuffed with a great time for me and my office peers to search your site at least 3 times in one week to study the newest stuff you have. And of course, we are at all times impressed concerning the brilliant methods you give. Certain two points in this post are completely the simplest we have all ever had.

Add new comment | arxic Drupal

An outstanding share! I've just forwarded this onto a colleague who has been doing a little research on this.

And he in fact bought me dinner due to the fact that
I found it for him... lol. So allow me to reword this....
Thanks for the meal!! But yeah, thanx for spending some time to discuss this matter here on your site.

Add new comment | arxic Drupal

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog when you could be giving us something informative to read?

Pages

Add new comment