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

chrome hearts online store

I'm also writing to make you understand of the remarkable encounter my cousin's child obtained checking your site. She realized too many issues, which include what it is like to have a very effective giving spirit to get men and women really easily know just exactly various tortuous topics. You truly did more than our own expected results. Thank you for displaying those effective, dependable, explanatory as well as fun guidance on that topic to Ethel.

Add new comment | arxic Drupal

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored
subject matter stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following.
unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this hike.

nike air max

I want to show appreciation to you for rescuing me from this particular condition. Right after surfing around throughout the world-wide-web and getting tricks that were not productive, I assumed my life was over. Being alive minus the strategies to the difficulties you have solved by way of the guide is a critical case, and those that would have adversely affected my entire career if I hadn't come across your web blog. Your primary knowledge and kindness in dealing with the whole lot was excellent. I don't know what I would have done if I hadn't come across such a step like this. I can also at this point relish my future. Thanks for your time very much for your impressive and result oriented guide. I will not think twice to recommend your web blog to any person who ought to have guidance on this problem.

kyrie 5 spongebob

My wife and i have been really relieved Peter could conclude his preliminary research with the ideas he grabbed in your web pages. It is now and again perplexing to simply continually be offering techniques many others might have been selling. And we also grasp we've got the blog owner to thank for this. The type of illustrations you've made, the simple website navigation, the relationships you can make it easier to engender - it's mostly amazing, and it's making our son and us do think that idea is thrilling, which is certainly truly fundamental. Thank you for everything!

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

Add new comment | arxic Drupal

Your style is so unique in comparison to other people I've read stuff from.
Thanks for posting when you've got the opportunity,
Guess I will just bookmark this web site.

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.

Add new comment | arxic Drupal

For latest information you have to pay a quick visit world-wide-web and on world-wide-web I found this
web site as a finest web site for latest updates.

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

Add new comment | arxic Drupal

Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I
acquire actually enjoyed account your blog posts.
Anyway I will be subscribing to your augment and even I
achievement you access consistently fast.

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

Add new comment | arxic Drupal

What's Going down i am new to this, I stumbled upon this I've found It absolutely helpful and it
has helped me out loads. I am hoping to give a contribution & assist other customers like its aided
me. Good job.

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!

Add new comment | arxic Drupal

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

Do you have any methods to stop hackers?

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.

Add new comment | arxic Drupal

My partner and I stumbled over here different web address and thought I should check things out.
I like what I see so now i'm following you. Look forward to looking over your web page again.

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.

Add new comment | arxic Drupal

Hi, Neat post. There's an issue together with your site in internet explorer,
would test this? IE still is the marketplace chief and a good portion of other folks will miss
your great writing because of this problem.

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.

coach factory outlet

I simply wanted to say thanks again. I'm not certain the things I would have taken care of in the absence of the entire solutions shared by you over my area. It truly was the scary matter in my opinion, but finding out your professional strategy you handled it made me to leap over fulfillment. I'm happy for your guidance and thus pray you comprehend what an amazing job you're carrying out teaching other individuals via your websites. More than likely you have never met any of us.

Add new comment | arxic Drupal

You've made some decent points there. I checked on the net for
additional information about the issue and found
most individuals will go along with your views on this web site.

ferragamo belt

I wanted to type a brief note to be able to express gratitude to you for those stunning strategies you are giving out at this website. My considerable internet lookup has at the end been rewarded with brilliant facts and strategies to share with my good friends. I would repeat that most of us site visitors are undeniably endowed to dwell in a magnificent community with so many outstanding professionals with interesting tips and hints. I feel really blessed to have seen your entire web pages and look forward to many more entertaining moments reading here. Thanks a lot once more for everything.

Add new comment | arxic Drupal

Excellent goods from you, man. I have bear in mind your stuff previous
to and you're just extremely excellent. I really like what you have bought right here, certainly like
what you're saying and the way in which you are saying it.
You're making it enjoyable and you continue to care for to stay it smart.
I can not wait to read far more from you.

That is really a great site.

kyrie 6

I and also my friends ended up analyzing the good tips and tricks from your website and so all of the sudden got an awful suspicion I had not thanked you for those tips. All the boys were totally passionate to read all of them and already have really been having fun with them. Thanks for being indeed thoughtful and also for making a choice on varieties of remarkable guides most people are really eager to be aware of. My personal honest apologies for not expressing appreciation to sooner.

Add new comment | arxic Drupal

I've been browsing online more than 4 hours today, yet I
never found any interesting article like yours. It's pretty worth enough for me.
Personally, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.

golden goose

I as well as my pals appeared to be checking the good items on your web blog while suddenly I had a terrible feeling I had not expressed respect to the blog owner for those techniques. All the men were thrilled to read all of them and have in effect seriously been making the most of them. I appreciate you for getting indeed thoughtful as well as for going for this form of great useful guides millions of individuals are really eager to be informed on. My personal sincere apologies for not expressing appreciation to earlier.

calvin klein outlet

I needed to post you one bit of word to finally thank you so much over again on the breathtaking pointers you've contributed above. It's simply unbelievably generous of you to convey openly all that a few individuals could have marketed for an electronic book to get some bucks on their own, most importantly considering that you might have done it if you decided. The solutions also acted to become good way to be certain that many people have the identical zeal the same as mine to know more and more when it comes to this condition. I'm certain there are some more pleasant instances ahead for many who go through your blog.

golden goose sneakers

I and also my guys ended up digesting the nice tips located on the blog and quickly I got an awful feeling I never expressed respect to you for those secrets. The ladies were for that reason very interested to study all of them and have now in fact been taking advantage of those things. Thanks for truly being simply thoughtful and for finding this sort of wonderful useful guides most people are really desirous to know about. My honest regret for not expressing gratitude to you sooner.

Add new comment | arxic Drupal

Today, I went to the beachfront with my children. I found a sea shell and gave
it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear and
screamed. There was a hermit crab inside and it pinched
her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

cheap jordan shoes

I intended to put you the little bit of word to be able to say thank you again with the incredible tricks you've shown in this case. This has been certainly seriously open-handed of you in giving unhampered all that numerous people would've made available for an electronic book to help make some cash on their own, most importantly considering the fact that you might have tried it if you considered necessary. Those inspiring ideas also acted like the easy way to fully grasp other individuals have the identical dream just as mine to figure out great deal more concerning this problem. I know there are lots of more pleasant instances up front for those who scan through your blog.

Add new comment | arxic Drupal

I'm not sure why but this weblog is loading incredibly slow for me.
Is anyone else having this issue or is it a issue on my end?

I'll check back later and see if the problem still exists.

moncler

I simply wished to say thanks yet again. I'm not certain what I could possibly have followed without the type of tactics discussed by you about such subject. Entirely was a very frustrating scenario in my position, nevertheless spending time with the specialized approach you handled that took me to jump over gladness. Now i'm happier for your support and as well , hope that you find out what a great job you're doing teaching people via your blog post. I'm certain you haven't encountered all of us.

salvatore ferragamo belt

Thank you a lot for giving everyone remarkably memorable opportunity to check tips from this site. It is always so beneficial and jam-packed with a great time for me personally and my office fellow workers to search your web site not less than 3 times per week to see the new things you will have. Of course, I'm so at all times amazed for the splendid concepts you give. Selected two areas on this page are certainly the simplest I have had.

Add new comment | arxic Drupal

Admiring the hard work you put into your site and in depth information you offer.

It's good to come across a blog every once in a while that isn't the same
outdated rehashed material. Excellent read! I've bookmarked
your site and I'm adding your RSS feeds to my Google account.

nike air vapormax

I would like to point out my respect for your kindness for individuals who have the need for guidance on the subject matter. Your personal commitment to getting the message all around has been incredibly beneficial and have surely encouraged employees like me to achieve their endeavors. Your own insightful suggestions denotes so much a person like me and even more to my office workers. Many thanks; from everyone of us.

Add new comment | arxic Drupal

This design is steller! You most certainly
know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Fantastic job.

I really enjoyed what you had to say, and more than that, how you presented it.

Too cool!

yeezy shoes

Needed to send you one bit of observation to finally thank you yet again relating to the superb guidelines you have provided on this page. It's really pretty generous of you to give unreservedly precisely what a number of us could have offered for an ebook in order to make some money for themselves, mostly now that you could have done it if you ever considered necessary. Those strategies additionally served to be the good way to be aware that many people have similar eagerness the same as mine to know the truth lots more with regard to this issue. Certainly there are thousands of more pleasant opportunities ahead for individuals who take a look at your blog post.

Add new comment | arxic Drupal

Hey there! I understand this is kind of off-topic however I had to ask.

Does running a well-established blog like yours require a massive amount work?

I am completely new to operating a blog but I do write in my diary every day.
I'd like to start a blog so I can share my experience and views online.
Please let me know if you have any kind of suggestions or tips for brand new aspiring bloggers.

Thankyou!

yeezy shoes

I would like to get across my respect for your kindness for men and women that must have assistance with in this area. Your very own dedication to getting the message all-around had been definitely good and has specifically enabled men and women like me to realize their endeavors. Your amazing invaluable useful information can mean much to me and somewhat more to my mates. With thanks; from each one of us.

Pages

Add new comment