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.

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.

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!?

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

curry 4

I was more than happy to find this internet-site.I wanted to thanks on your time for this glorious learn!! I definitely enjoying every little little bit of it and I've you bookmarked to take a look at new stuff you weblog post.

hermes online

Aw, this was a very nice post. In idea I would like to put in writing like this moreover ?taking time and actual effort to make a very good article?but what can I say?I procrastinate alot and on no account seem to get one thing done.

golden goose

Can I simply say what a aid to search out someone who really knows what theyre speaking about on the internet. You undoubtedly know how you can bring a difficulty to gentle and make it important. More individuals need to learn this and understand this side of the story. I cant believe youre no more popular since you undoubtedly have the gift.

nike air max

When I initially commented I clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the same comment. Is there any approach you'll be able to remove me from that service? Thanks!

ferragamo belt

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

yeezy boost 350

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

jordan 6

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

curry shoes

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

curry 5

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

louboutin shoes uk

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

michael jordan shoes

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

balenciaga

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

yeezy shoes

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

westbrook shoes

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

balenciaga

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

kate spade handbags

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

Add new comment | arxic Drupal

Thank you for every other informative website. Where else may just
I get that type of information written in such a perfect way?
I have a mission that I'm just now operating on, and I have been on the glance
out for such info.

Add new comment | arxic Drupal

You really make it seem so easy with your presentation but I find this matter to
be actually something that I think I would never understand.

It seems too complicated and extremely broad for me.
I am looking forward for your next post, I'll
try to get the hang of it!

nfl jerseys

An interesting dialogue is value comment. I think that it is best to write more on this subject, it might not be a taboo subject but generally individuals are not sufficient to speak on such topics. To the next. Cheers

off white

Can I simply say what a reduction to search out someone who really is aware of what theyre speaking about on the internet. You definitely know find out how to deliver a difficulty to light and make it important. Extra individuals must learn this and understand this aspect of the story. I cant believe youre not more in style since you positively have the gift.

nike air max

I抎 must examine with you here. Which is not something I normally do! I take pleasure in reading a publish that will make individuals think. Also, thanks for allowing me to remark!

converse shoes

I抎 need to verify with you here. Which isn't something I normally do! I get pleasure from studying a post that will make people think. Additionally, thanks for permitting me to comment!

supreme hoodie

I am typically to blogging and i really recognize your content. The article has really peaks my interest. I'm going to bookmark your website and keep checking for brand spanking new information.

yeezy shoes

Thank you so much for providing individuals with an exceptionally marvellous chance to read articles and blog posts from here. It is always very excellent and as well , full of a great time for me personally and my office peers to visit your site the equivalent of 3 times weekly to learn the latest things you will have. And indeed, I am just actually pleased with your fantastic suggestions served by you. Selected 3 points on this page are certainly the best we have ever had.

yeezy boost 700

Thank you for your own hard work on this web page. My niece takes pleasure in participating in internet research and it's really easy to understand why. A number of us notice all regarding the dynamic medium you produce very important information by means of this website and therefore cause response from others about this theme so our daughter is always learning a lot of things. Take pleasure in the remaining portion of the new year. You're doing a good job.

yeezy boost 350

I must show some thanks to the writer for rescuing me from this type of condition. After browsing through the the web and seeing views which are not beneficial, I assumed my entire life was done. Living without the presence of strategies to the issues you've resolved as a result of your blog post is a serious case, and the ones which may have adversely affected my career if I had not discovered the blog. Your own personal capability and kindness in maneuvering all areas was crucial. I don't know what I would have done if I had not come upon such a thing like this. I can also at this time relish my future. Thanks for your time very much for this expert and sensible guide. I won't be reluctant to suggest the sites to any individual who will need guidelines on this situation.

Pages

Add new comment