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

Kanye West shoes

I really wanted to develop a comment to be able to say thanks to you for those fantastic solutions you are showing on this site. My incredibly long internet investigation has finally been compensated with good quality information to talk about with my classmates and friends. I would claim that most of us website visitors are quite blessed to live in a good community with many lovely people with beneficial principles. I feel very fortunate to have encountered your entire web pages and look forward to so many more thrilling minutes reading here. Thanks once again for everything.

supreme t shirt

I intended to post you this little bit of observation to give many thanks over again over the striking suggestions you have discussed at this time. This is certainly tremendously open-handed of people like you to supply without restraint just what most people would've marketed as an electronic book to help with making some bucks for their own end, most notably since you could possibly have done it in the event you desired. Those guidelines likewise worked as the great way to fully grasp other individuals have the identical interest like my own to understand very much more regarding this problem. I'm sure there are many more fun situations ahead for folks who find out your blog.

Add new comment | arxic Drupal

I've been browsing on-line greater than three hours lately, but
I never discovered any interesting article like yours.
It is pretty price enough for me. In my opinion, if all webmasters and bloggers made excellent
content material as you did, the internet will be a lot more helpful than ever before.

michael kors handbags

My wife and i got so joyous that Emmanuel could complete his investigations because of the ideas he made out of the weblog. It's not at all simplistic to just continually be giving out tips and tricks which other folks may have been selling. And we grasp we now have the website owner to thank because of that. These explanations you've made, the easy site menu, the relationships you can make it possible to foster - it's all astonishing, and it's making our son and the family reckon that the concept is interesting, which is incredibly vital. Many thanks for the whole thing!

Add new comment | arxic Drupal

If some one needs expert view concerning running
a blog afterward i advise him/her to pay a
quick visit this website, Keep up the pleasant work.

kd 11 shoes

I not to mention my guys were going through the nice thoughts from your web site and then immediately I had an awful feeling I had not thanked the web site owner for those tips. All the men were consequently excited to read through all of them and have now in truth been tapping into those things. Appreciation for actually being quite kind as well as for obtaining some extraordinary subject matter most people are really eager to learn about. My sincere regret for not expressing appreciation to sooner.

converse outlet

I happen to be writing to make you understand what a awesome encounter my friend's child undergone reading your web page. She came to find a lot of pieces, with the inclusion of what it's like to have an excellent giving spirit to have the others with ease learn about some problematic topics. You undoubtedly surpassed our expectations. I appreciate you for presenting these interesting, trustworthy, educational and as well as easy tips on this topic to Gloria.

Add new comment | arxic Drupal

My brother suggested I would possibly like this web site.

He was once entirely right. This publish actually made my day.

You cann't consider simply how so much time I
had spent for this information! Thank you!

adidas yeezy

Thanks a lot for providing individuals with an extremely breathtaking opportunity to read critical reviews from this web site. It's usually so excellent and also stuffed with amusement for me personally and my office fellow workers to visit your blog at minimum three times per week to read the latest issues you have got. Not to mention, we're always fascinated with your incredible suggestions you give. Certain 2 ideas on this page are ultimately the most suitable I have had.

Add new comment | arxic Drupal

Hi there, i read your blog from time to time and i own a similar one and i was just curious if you
get a lot of spam feedback? If so how do you stop it, any plugin or anything you can advise?
I get so much lately it's driving me insane so any
assistance is very much appreciated.

kd 10

I simply needed to thank you very much yet again. I am not sure the things I could possibly have implemented in the absence of the entire recommendations documented by you relating to that area. It truly was a real depressing dilemma in my opinion, however , discovering your expert form you solved it made me to leap over delight. I am just happy for this support and then trust you know what a powerful job your are carrying out instructing others using a site. I am certain you have never encountered all of us.

Add new comment | arxic Drupal

Wow that was odd. I just wrote an incredibly long comment
but after I clicked submit my comment didn't appear. Grrrr...
well I'm not writing all that over again. Anyways, just wanted to say great blog!

christian louboutin outlet

Thanks for every one of your efforts on this web site. Gloria delights in conducting internet research and it's easy to see why. A lot of people notice all relating to the compelling way you create reliable ideas through the web site and in addition inspire response from some other people about this matter then our simple princess is without question learning a great deal. Take advantage of the remaining portion of the year. You are doing a wonderful job.

supreme shirt

I have to show my appreciation to the writer for bailing me out of this particular crisis. Right after looking out throughout the world-wide-web and coming across ideas which are not helpful, I was thinking my life was gone. Being alive without the approaches to the difficulties you've solved as a result of the posting is a critical case, as well as those which may have adversely affected my career if I hadn't encountered the blog. Your own personal talents and kindness in dealing with all the stuff was helpful. I am not sure what I would have done if I had not discovered such a point like this. It's possible to at this time relish my future. Thanks so much for your reliable and effective help. I won't hesitate to refer the sites to any individual who needs guidance about this situation.

Add new comment | arxic Drupal

Today, I went to the beach front with my kids. 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 put 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 completely off topic but I had to tell someone!

supreme clothing

I would like to point out my passion for your generosity giving support to folks that require help with the idea. Your special commitment to getting the message across became pretty informative and has all the time encouraged women just like me to achieve their dreams. This insightful useful information means a lot a person like me and substantially more to my mates. With thanks; from everyone of us.

Add new comment | arxic Drupal

Hey there, You've done an incredible job. I'll definitely digg it and personally suggest to
my friends. I am sure they'll be benefited from
this website.

longchamp outlet

Needed to compose you a very small note to help thank you very much yet again on your magnificent methods you have documented in this article. It was quite open-handed of people like you to make freely all that a number of people could have marketed as an ebook to earn some dough for themselves, principally now that you could have tried it in case you decided. The creative ideas likewise acted as a easy way to fully grasp that most people have a similar zeal the same as my own to learn more and more when it comes to this problem. I am sure there are many more fun times ahead for folks who go through your blog.

Add new comment | arxic Drupal

Fine way of explaining, and nice post to obtain information on the topic of my presentation subject, which i am going to deliver in university.

michael kors

I needed to put you that little remark to say thank you the moment again for your personal extraordinary solutions you've discussed at this time. It has been simply open-handed with you to make without restraint all most of us would have offered for sale as an electronic book in making some dough for themselves, and in particular considering the fact that you might well have tried it if you ever desired. These concepts in addition served to be a easy way to be sure that many people have a similar dream the same as my very own to learn whole lot more when it comes to this matter. I'm sure there are many more fun situations in the future for individuals who read carefully your website.

Add new comment | arxic Drupal

Woah! I'm really enjoying the template/theme of this blog.

It's simple, yet effective. A lot of times it's difficult to
get that "perfect balance" between superb usability and appearance.
I must say you have done a great job with this. In addition, the blog loads extremely fast for me on Chrome.
Outstanding Blog!

golden goose shoes

I really wanted to write a quick comment so as to say thanks to you for these fantastic suggestions you are sharing at this website. My rather long internet research has now been rewarded with reputable details to go over with my company. I 'd claim that most of us readers actually are really lucky to live in a remarkable site with very many awesome professionals with beneficial secrets. I feel somewhat happy to have discovered the web site and look forward to really more pleasurable minutes reading here. Thanks a lot once again for everything.

Add new comment | arxic Drupal

Whats up very cool website!! Guy .. Beautiful ..
Amazing .. I will bookmark your website and take the feeds additionally?
I'm happy to find numerous helpful info right here in the submit, we need develop more techniques on this regard,
thank you for sharing. . . . . .

nike react

I together with my buddies were found to be examining the excellent helpful hints found on the website and immediately I got an awful suspicion I never expressed respect to the blog owner for those secrets. Most of the people happened to be as a consequence stimulated to learn them and already have seriously been having fun with those things. Many thanks for being well thoughtful as well as for obtaining varieties of superb issues most people are really desirous to be aware of. Our sincere apologies for not expressing gratitude to you earlier.

Add new comment | arxic Drupal

You've made some good points there. I checked on the net to find out more about the issue and found most individuals
will go along with your views on this site.

hermes handbags

I needed to put you that bit of remark just to say thank you again for the marvelous concepts you've shown at this time. It's simply tremendously generous with you to deliver easily all that a number of people might have offered for an e book to help with making some cash on their own, primarily seeing that you could have tried it if you ever wanted. Those strategies additionally acted to be a great way to recognize that some people have the same keenness similar to mine to find out lots more with regard to this issue. I'm sure there are many more pleasant periods up front for people who read your blog post.

coach bags sale

I am glad for writing to let you know of the terrific discovery my wife's girl enjoyed reading your blog. She discovered some details, not to mention what it's like to possess a great coaching nature to let many others completely completely grasp a variety of complex things. You undoubtedly exceeded people's desires. Thanks for providing those great, trustworthy, edifying and unique tips on your topic to Tanya.

Add new comment | arxic Drupal

What's up all, here every one is sharing these kinds of knowledge, so it's nice to read this webpage,
and I used to pay a visit this weblog everyday.

Add new comment | arxic Drupal

Wonderful beat ! I would like to apprentice while you amend your
website, how can i subscribe for a blog web site? The account aided me
a acceptable deal. I had been tiny bit acquainted of
this your broadcast offered bright clear concept

Add new comment | arxic Drupal

Oh my goodness! Amazing article dude! Thanks, However I am
experiencing problems with your RSS. I don't know the reason why I can't join it.

Is there anyone else getting the same RSS problems? Anybody
who knows the answer can you kindly respond? Thanx!!

Add new comment | arxic Drupal

Nice weblog here! Additionally your site a lot up fast!
What host are you using? Can I am getting your affiliate hyperlink on your host?
I want my site loaded up as quickly as yours lol

Add new comment | arxic Drupal

Do you mind if I quote a few of your posts as long as I provide credit and sources back to your blog?
My website is in the very same area of interest as yours and my users would definitely benefit from a lot of the information you
present here. Please let me know if this alright with you.
Cheers!

balenciaga shoes

Hey! I simply want to give an enormous thumbs up for the great info you've gotten right here on this post. I will likely be coming back to your weblog for extra soon.

Add new comment | arxic Drupal

Terrific article! This is the kind of information that should be shared
across the net. Disgrace on the seek engines for no longer positioning this put up upper!
Come on over and seek advice from my site .
Thanks =)

yeezy boost

An impressive share, I just given this onto a colleague who was doing a little bit evaluation on this. And he actually bought me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If possible, as you turn out to be experience, would you thoughts updating your weblog with extra details? It's extremely helpful for me. Big thumb up for this weblog put up!

Add new comment | arxic Drupal

Hello! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche.

Your blog provided us useful information to work
on. You have done a wonderful job!

nike air max 97

After research a couple of of the blog posts on your website now, and I really like your approach of blogging. I bookmarked it to my bookmark web site record and will probably be checking again soon. Pls try my web page as nicely and let me know what you think.

Add new comment | arxic Drupal

fantastic points altogether, you simply received a brand new reader.
What might you suggest in regards to your submit that you made
some days ago? Any certain?

fitflops sale clearance

There are some interesting cut-off dates in this article but I don抰 know if I see all of them middle to heart. There's some validity but I'll take hold opinion till I look into it further. Good article , thanks and we want extra! Added to FeedBurner as nicely

mbt shoes

An interesting dialogue is price comment. I feel that it is best to write extra on this topic, it might not be a taboo subject but typically persons are not enough to speak on such topics. To the next. Cheers

Add new comment | arxic Drupal

Can I simply just say what a relief to uncover an individual who
actually understands what they are talking about
online. You certainly realize how to bring an issue to light and make it important.
More people really need to read this and understand this side of the story.
It's surprising you aren't more popular because you surely
have the gift.

Add new comment | arxic Drupal

whoah this weblog is fantastic i like studying your articles.
Keep up the good work! You know, many persons are looking round for this information,
you could aid them greatly.

Pages

Add new comment