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

timberland outlet

I am glad for commenting to let you be aware of what a fabulous discovery our child had checking the blog. She came to understand numerous pieces, with the inclusion of how it is like to have a wonderful giving style to let other folks smoothly understand various extremely tough matters. You undoubtedly exceeded our expected results. I appreciate you for distributing such necessary, safe, revealing and as well as easy thoughts on that topic to Tanya.

Add new comment | arxic Drupal

Hi, I do believe this is a great site. I stumbledupon it ;
) I may return once again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

yeezy

I not to mention my buddies have been looking at the good key points located on your web site and then then I got a terrible suspicion I never thanked the website owner for those techniques. All of the people became consequently passionate to see all of them and have now actually been making the most of them. Thank you for actually being simply thoughtful as well as for making a choice on such amazing areas most people are really wanting to discover. My very own sincere regret for not expressing gratitude to you sooner.

Add new comment | arxic Drupal

My spouse and I stumbled over here different web
address and thought I might as well check things out.
I like what I see so now i am following you. Look forward to looking
into your web page repeatedly.

fila shoes

I needed to write you that little bit of note to give many thanks over again relating to the beautiful guidelines you have documented on this page. This is simply extremely open-handed with you in giving extensively what exactly most of us could have made available as an e book to make some cash for their own end, mostly since you might have tried it in case you considered necessary. These strategies also worked to provide a good way to recognize that other individuals have similar desire like my own to realize a lot more with reference to this problem. I am sure there are many more pleasant situations ahead for many who looked at your blog.

Add new comment | arxic Drupal

I'm amazed, I must say. Rarely do I encounter a blog
that's both educative and interesting, and let me tell you, you have hit
the nail on the head. The issue is something that too few folks are speaking intelligently about.
I am very happy I came across this in my search for something regarding this.

yeezy boost 350

I precisely desired to appreciate you again. I am not sure what I might have carried out without the entire tips and hints discussed by you directly on such area of interest. It was before a real hard dilemma in my opinion, however , looking at this well-written avenue you solved that forced me to weep for contentment. I am happier for this information and as well , have high hopes you realize what a great job your are doing instructing the others via a blog. I am sure you've never got to know all of us.

Add new comment | arxic Drupal

Neat blog! Is your theme custom made or did you download it from
somewhere? A design like yours with a few simple tweeks would really make my blog jump out.
Please let me know where you got your theme. Many thanks

chrome hearts online

I am commenting to let you be aware of what a outstanding discovery our princess enjoyed viewing your web page. She picked up a wide variety of things, most notably what it's like to have a marvelous coaching style to let most people really easily know certain complicated subject areas. You truly did more than her expectations. Thank you for supplying those interesting, dependable, informative and in addition easy thoughts on the topic to Emily.

Add new comment | arxic Drupal

each time i used to read smaller articles or reviews which as well clear their motive, and that is
also happening with this article which I am reading at this
time.

yeezy boost 350

My spouse and i got really excited that Louis managed to deal with his inquiry with the precious recommendations he received out of the web page. It's not at all simplistic to simply choose to be giving freely points that many other folks might have been making money from. We do know we have the blog owner to thank for this. The illustrations you made, the simple website navigation, the friendships your site make it possible to engender - it's got most fabulous, and it's really helping our son in addition to our family reason why the subject matter is awesome, and that's highly important. Thanks for all!

jordan shoes

A lot of thanks for your entire effort on this site. My aunt take interest in participating in internet research and it's easy to see why. A number of us know all regarding the dynamic way you give both useful and interesting steps via this website and even foster participation from visitors about this matter plus our favorite daughter is without question discovering a great deal. Take advantage of the rest of the year. You're the one conducting a pretty cool job.

Add new comment | arxic Drupal

Sweet blog! I found it while searching on Yahoo News.
Do you have any tips on how to get listed in Yahoo News? I've been trying for a while but I never
seem to get there! Many thanks

lebron 15 shoes

I want to express some appreciation to the writer for rescuing me from this circumstance. Right after exploring throughout the online world and finding advice which were not pleasant, I believed my entire life was well over. Existing minus the strategies to the issues you've resolved by way of your main guide is a serious case, and those which may have adversely damaged my entire career if I hadn't discovered your site. Your primary capability and kindness in taking care of all areas was vital. I don't know what I would have done if I had not come across such a solution like this. It's possible to at this time look ahead to my future. Thanks very much for this reliable and results-oriented guide. I won't be reluctant to propose your web site to any person who requires assistance about this problem.

Add new comment | arxic Drupal

I have been exploring for a little bit for any high-quality articles or weblog
posts on this kind of space . Exploring in Yahoo I at last stumbled upon this web site.
Reading this information So i am glad to convey that I've a
very good uncanny feeling I found out exactly what I needed.
I most for sure will make certain to do not omit this web site
and give it a look on a relentless basis.

nike kyrie 5

I and my friends were taking note of the nice strategies found on your website and so immediately I got a terrible suspicion I had not thanked the site owner for those secrets. My boys were definitely for this reason happy to read through them and have in truth been enjoying them. Appreciate your indeed being quite accommodating as well as for settling on such exceptional tips millions of individuals are really eager to know about. My very own sincere apologies for not expressing gratitude to earlier.

Add new comment | arxic Drupal

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

cheap jordans

I just wanted to type a simple comment to be able to express gratitude to you for some of the unique ways you are sharing here. My extended internet research has at the end of the day been paid with pleasant facts and strategies to talk about with my visitors. I would admit that we visitors actually are unequivocally fortunate to dwell in a fabulous place with so many wonderful professionals with valuable secrets. I feel very much lucky to have encountered your webpage and look forward to plenty of more pleasurable moments reading here. Thanks once again for everything.

Add new comment | arxic Drupal

I'm amazed, I must say. Rarely do I come across
a blog that's both equally educative and engaging, and without a doubt,
you've hit the nail on the head. The problem is something that too few
people are speaking intelligently about. I'm very happy that I stumbled across this during
my hunt for something concerning this.

hermes belts for men

I and my pals appeared to be studying the best recommendations on your web site while unexpectedly I had a terrible feeling I never expressed respect to the web blog owner for those techniques. Most of the boys were for that reason excited to learn them and have in fact been using these things. Thanks for getting really considerate and also for making a decision on this kind of impressive subject matter millions of individuals are really wanting to be informed on. My honest regret for not saying thanks to earlier.

Add new comment | arxic Drupal

Thank you, I've recently been searching for information approximately this subject for ages and yours is the greatest
I've came upon till now. But, what in regards to the
conclusion? Are you certain about the supply?

yeezy boost 350 v2

I would like to express my love for your generosity supporting persons who need guidance on this one matter. Your real commitment to getting the message along was incredibly interesting and have really made men and women much like me to achieve their endeavors. Your new helpful key points can mean this much a person like me and even further to my peers. Thanks a ton; from everyone of us.

Add new comment | arxic Drupal

Hi there, just became alert to your blog through Google, and found that it's truly informative.

I am going to watch out for brussels. I'll appreciate if you continue
this in future. A lot of people will be benefited from your
writing. Cheers!

golden goose

I'm also writing to let you be aware of of the great discovery our child had reading yuor web blog. She came to find many pieces, which included what it is like to have an excellent teaching heart to make the rest quite simply learn about chosen complex matters. You truly did more than our own expected results. I appreciate you for delivering the essential, safe, revealing and even fun thoughts on that topic to Jane.

Add new comment | arxic Drupal

When someone writes an article he/she keeps the image of a
user in his/her mind that how a user can be
aware of it. So that's why this piece of writing is amazing.
Thanks!

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

Pages

Add new comment