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

lebron 17

I actually wanted to send a message to be able to thank you for all the magnificent suggestions you are writing on this website. My long internet investigation has at the end been rewarded with excellent know-how to talk about with my company. I would claim that we site visitors are very much fortunate to exist in a very good site with very many brilliant people with good hints. I feel very much happy to have come across your entire website and look forward to really more fabulous moments reading here. Thank you once again for a lot of things.

Add new comment | arxic Drupal

Hola! I've been following your web site for a long time now and
finally got the bravery to go ahead and give you a shout out from
Lubbock Texas! Just wanted to mention keep up the good
job!

converse shoes

I and also my friends have already been reading through the best solutions located on the blog and so quickly developed an awful feeling I never thanked the web site owner for those techniques. Those young men happened to be consequently glad to read them and have now definitely been tapping into those things. Appreciation for actually being very considerate and for pick out these kinds of really good topics millions of individuals are really wanting to understand about. My very own sincere regret for not expressing appreciation to you earlier.

Add new comment | arxic Drupal

You actually make it seem so easy with your presentation but I find this matter to be
really something that I think I would never understand.
It seems too complicated and very broad for me.
I'm looking forward for your next post, I will try to get the hang
of it!

kd 11 shoes

I intended to put you that bit of word just to thank you yet again regarding the lovely secrets you have discussed above. It is simply unbelievably open-handed of people like you to provide publicly precisely what a few people could possibly have marketed for an e-book in order to make some bucks for their own end, certainly given that you might have done it in case you decided. Those suggestions likewise acted like the great way to recognize that other people have the same fervor really like my personal own to know the truth whole lot more in respect of this condition. I'm certain there are many more enjoyable occasions in the future for individuals that check out your blog.

Add new comment | arxic Drupal

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

off white hoodie

I wish to express appreciation to the writer just for rescuing me from such a predicament. Because of scouting through the world wide web and seeing proposals which are not productive, I thought my life was over. Living without the strategies to the problems you've fixed by way of this short post is a critical case, as well as ones which could have badly affected my career if I had not discovered your web site. The mastery and kindness in controlling every item was helpful. I am not sure what I would have done if I hadn't encountered such a step like this. It's possible to at this moment look forward to my future. Thank you very much for the professional and sensible guide. I won't think twice to endorse your site to any individual who would need guidance on this topic.

golden goose outlet

I and also my friends happened to be going through the excellent thoughts from your website and then suddenly I had an awful suspicion I had not thanked the web site owner for those secrets. The young men became totally happy to learn them and now have certainly been having fun with these things. Thanks for simply being really considerate and for picking this sort of nice subjects most people are really wanting to learn about. Our honest regret for not expressing gratitude to earlier.

Add new comment | arxic Drupal

Yesterday, while I was at work, my sister stole my iphone and
tested to see if it can survive a thirty foot
drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.
I know this is completely off topic but I had to share it
with someone!

Add new comment | arxic Drupal

My brother suggested I might like this blog.
He was entirely right. This post truly made my day. You cann't
imagine simply how much time I had spent for this information! Thanks!

air max 97

You made some respectable factors there. I seemed on the internet for the difficulty and found most people will go together with together with your website.

air max 95

It is best to take part in a contest for among the best blogs on the web. I will advocate this site!

yeezy

A powerful share, I simply given this onto a colleague who was doing slightly analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying more on this topic. If attainable, as you turn into experience, would you thoughts updating your blog with more particulars? It's highly helpful for me. Huge thumb up for this blog post!

Add new comment | arxic Drupal

I was curious if you ever considered changing the layout of your site?

Its very well written; I love what youve got to say. But
maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having one or two pictures.
Maybe you could space it out better?

nike air max

Aw, this was a very nice post. In thought I wish to put in writing like this additionally ?taking time and precise effort to make an excellent article?but what can I say?I procrastinate alot and in no way appear to get something done.

Add new comment | arxic Drupal

Hey there! I know this is kind of off topic but I was wondering which blog platform are you using for this
site? I'm getting fed up of Wordpress because I've had problems with hackers
and I'm looking at alternatives for another platform. I would be
awesome if you could point me in the direction of a good platform.

Add new comment | arxic Drupal

Hi there just wanted to give you a brief heads up and let you know a few of the images
aren't loading properly. I'm not sure why but I think its a linking issue.
I've tried it in two different web browsers and
both show the same results.

fitflop

I discovered your weblog web site on google and verify a few of your early posts. Proceed to maintain up the superb operate. I simply additional up your RSS feed to my MSN News Reader. Searching for forward to reading extra from you afterward!?

hogan outlet

I and also my buddies were found to be viewing the great information from your web blog and then all of the sudden I got a terrible feeling I had not expressed respect to the web site owner for those tips. All the guys had been consequently stimulated to learn all of them and already have really been having fun with them. Many thanks for getting quite considerate and then for choosing varieties of marvelous things most people are really desirous to be informed on. Our honest apologies for not saying thanks to you sooner.

Add new comment | arxic Drupal

Fantastic beat ! I wish to apprentice while you amend your website, how could i subscribe for a blog
website? The account aided me a acceptable deal.
I had been tiny bit acquainted of this your broadcast provided bright clear idea

yeezy 700

I am just commenting to make you understand what a remarkable discovery my wife's child experienced reading through yuor web blog. She mastered many issues, which included what it's like to possess an excellent coaching heart to get a number of people without problems understand a number of problematic topics. You really did more than our own expectations. I appreciate you for producing such insightful, healthy, explanatory as well as easy tips about this topic to Mary.

Add new comment | arxic Drupal

Link exchange is nothing else except it is
simply placing the other person's website link on your page at
proper place and other person will also do same in support of you.

nike shoes

I have to get across my respect for your kind-heartedness supporting folks that absolutely need guidance on the issue. Your very own dedication to passing the message all around became extremely helpful and has all the time enabled many people like me to realize their dreams. Your insightful advice denotes a great deal a person like me and much more to my office workers. Regards; from each one of us.

cheap jordans

I would like to show appreciation to this writer just for bailing me out of this instance. After checking through the search engines and getting proposals that were not helpful, I thought my life was gone. Living devoid of the strategies to the problems you've solved by means of this short post is a critical case, and those which may have in a negative way affected my career if I hadn't noticed the website. Your personal skills and kindness in handling all areas was priceless. I am not sure what I would've done if I had not encountered such a solution like this. I can also now look ahead to my future. Thanks for your time so much for this reliable and effective help. I won't be reluctant to refer your site to anybody who should get guidance about this situation.

goyard handbags

I want to show my admiration for your generosity supporting visitors who absolutely need guidance on this theme. Your special dedication to passing the solution around ended up being pretty significant and have all the time helped employees much like me to arrive at their aims. The warm and friendly instruction entails this much to me and a whole lot more to my mates. Thanks a lot; from everyone of us.

bape hoodie

I happen to be writing to let you understand what a impressive experience my friend's girl found studying your webblog. She mastered a good number of pieces, most notably what it is like to have a wonderful giving mood to get the rest effortlessly gain knowledge of a number of multifaceted subject areas. You really surpassed our own expectations. Thank you for churning out these powerful, trustworthy, educational and also easy tips on this topic to Jane.

Add new comment | arxic Drupal

An impressive share! I've just forwarded this onto a coworker who had been conducting a little homework on this.
And he in fact ordered me dinner because I stumbled upon it for him...
lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanx for spending the
time to discuss this topic here on your blog.

salvatore ferragamo belt

I enjoy you because of all of your hard work on this web page. Ellie enjoys managing internet research and it is obvious why. Most people notice all regarding the lively method you present insightful guidelines via the website and as well as increase response from some others on this concept so our favorite simple princess is without question studying so much. Take pleasure in the rest of the new year. You are doing a pretty cool job.

Add new comment | arxic Drupal

Hi i am kavin, its my first time to commenting anywhere, when i read this piece of writing i thought i could also create comment due to
this good article.

nike foamposite

A lot of thanks for your own work on this site. Gloria take interest in doing internet research and it's really simple to grasp why. Many of us hear all concerning the dynamic ways you produce insightful items by means of the blog and as well as welcome participation from others on the subject plus my child is undoubtedly starting to learn a whole lot. Have fun with the remaining portion of the new year. You are always carrying out a glorious job.

Add new comment | arxic Drupal

Hello, I think your blog might be having browser compatibility issues.
When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.

I just wanted to give you a quick heads up! Other then that, amazing blog!

michael kors

I am just commenting to let you understand of the excellent discovery my friend's child experienced checking your blog. She came to find such a lot of pieces, not to mention what it is like to have an incredible giving nature to let others effortlessly know precisely some extremely tough things. You undoubtedly exceeded our own desires. Thank you for giving those practical, healthy, revealing as well as fun tips on that topic to Janet.

Add new comment | arxic Drupal

Spot on with this write-up, I truly feel this amazing site needs a lot more attention. I'll probably be back again to read through
more, thanks for the info!

golden goose sneakers

I must show some thanks to the writer just for bailing me out of this scenario. As a result of exploring through the internet and finding tricks which are not powerful, I thought my entire life was done. Being alive devoid of the strategies to the difficulties you've sorted out all through your main posting is a crucial case, as well as the kind which might have negatively damaged my career if I hadn't encountered your site. The ability and kindness in taking care of the whole thing was very useful. I'm not sure what I would've done if I hadn't come across such a subject like this. I'm able to at this time look forward to my future. Thanks very much for your skilled and results-oriented guide. I won't think twice to refer the website to anybody who desires guide about this situation.

Add new comment | arxic Drupal

I don't even know how I ended up here, but I thought this
post was great. I don't know who you are but certainly
you're going to a famous blogger if you aren't already ;
) Cheers!

air max 270

I want to show some appreciation to this writer for rescuing me from this type of condition. After browsing throughout the world-wide-web and meeting concepts which are not beneficial, I assumed my entire life was well over. Living without the presence of answers to the issues you have sorted out by way of this review is a critical case, as well as ones which could have adversely damaged my career if I hadn't encountered the blog. That know-how and kindness in controlling every aspect was very useful. I don't know what I would have done if I had not come upon such a subject like this. I am able to at this moment look ahead to my future. Thanks very much for your specialized and sensible guide. I won't hesitate to endorse your blog post to anybody who desires guidelines about this topic.

Add new comment | arxic Drupal

Thanks for your marvelous posting! I genuinely enjoyed reading it, you're
a great author.I will remember to bookmark your
blog and will come back in the foreseeable future.
I want to encourage you to continue your great
job, have a nice afternoon!

lebron shoes

I have to show thanks to you just for rescuing me from such a challenge. As a result of exploring throughout the world wide web and finding tips which are not helpful, I was thinking my entire life was well over. Existing minus the solutions to the issues you have resolved as a result of the website is a critical case, and those that would have in a negative way damaged my career if I had not come across your site. Your primary natural talent and kindness in dealing with everything was tremendous. I am not sure what I would've done if I hadn't encountered such a subject like this. It's possible to at this time look forward to my future. Thanks for your time so much for your skilled and results-oriented help. I will not be reluctant to refer your web page to anybody who needs tips on this area.

hermes bag

Thank you so much for providing individuals with remarkably brilliant opportunity to read articles and blog posts from this site. It is usually so pleasurable plus stuffed with a great time for me personally and my office peers to visit your site at least thrice in one week to see the fresh issues you have. And of course, we're actually satisfied concerning the breathtaking points you serve. Selected 4 facts in this posting are really the simplest we have all ever had.

Add new comment | arxic Drupal

Oh my goodness! Incredible article dude! Thank you so much, However I am
having issues with your RSS. I don't understand the reason why I can't subscribe to it.
Is there anybody else having similar RSS issues? Anyone
that knows the solution will you kindly
respond? Thanks!!

Pages

Add new comment