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

golden goose

I just wanted to make a quick note to appreciate you for these great information you are sharing here. My rather long internet look up has at the end been compensated with reputable concept to write about with my contacts. I would say that we visitors actually are very much lucky to live in a fantastic community with so many marvellous professionals with interesting things. I feel very grateful to have discovered your website and look forward to so many more enjoyable moments reading here. Thank you once again for a lot of things.

nike react

Thanks a lot for providing individuals with such a splendid chance to read critical reviews from this web site. It is usually very terrific and as well , jam-packed with a good time for me and my office fellow workers to search your site at the very least 3 times in a week to learn the new things you will have. And lastly, we are at all times contented with your attractive strategies you give. Certain 2 facts in this post are particularly the very best we have all ever had.

coach handbags

Needed to create you one very little remark in order to say thanks again on the wonderful strategies you have contributed here. It's really remarkably open-handed of you to allow publicly just what a lot of people would've made available as an e-book to help make some bucks on their own, certainly seeing that you might have done it if you wanted. Those tips in addition acted to become great way to know that other people online have similar interest just as my personal own to understand a good deal more with reference to this condition. I am certain there are thousands of more pleasurable times in the future for individuals that read through your blog post.

Add new comment | arxic Drupal

Excellent article. Keep writing such kind of info on your site.

Im really impressed by your site.
Hi there, You have performed an incredible job. I'll certainly digg it and personally suggest
to my friends. I'm confident they'll be benefited from this web site.

adidas stan smith men

I am only writing to let you know of the wonderful experience our daughter went through browsing your site. She learned a wide variety of pieces, including how it is like to possess an excellent helping nature to have a number of people clearly know just exactly a variety of complex topics. You really exceeded people's desires. Many thanks for delivering those effective, dependable, revealing and unique tips on your topic to Kate.

Add new comment | arxic Drupal

Hello! I know this is kinda off topic however I'd figured
I'd ask. Would you be interested in trading links or maybe guest authoring a blog post
or vice-versa? My website covers a lot of the same topics as
yours and I believe we could greatly benefit from each other.
If you might be interested feel free to shoot me an email.
I look forward to hearing from you! Great blog by the
way!

adidas nmd

I wish to express my appreciation to this writer just for rescuing me from this type of issue. As a result of scouting through the the net and coming across things which are not beneficial, I was thinking my life was gone. Existing minus the strategies to the difficulties you've solved through your main short article is a serious case, and the ones that would have adversely affected my career if I hadn't discovered your blog. The ability and kindness in playing with all things was very useful. I don't know what I would've done if I hadn't discovered such a point like this. I can also now look ahead to my future. Thank you very much for your professional and amazing help. I will not hesitate to endorse your web sites to anyone who will need counselling about this subject.

off white jordan 1

I simply needed to thank you so much all over again. I'm not certain the things I could possibly have taken care of in the absence of the strategies shown by you concerning such a problem. It was actually the hard case in my position, nevertheless being able to view this expert way you resolved that made me to cry with gladness. I am happy for this help and believe you know what an amazing job you are accomplishing training some other people with the aid of a site. Probably you've never come across any of us.

chrome hearts store

I in addition to my guys have been following the nice suggestions located on your web site then before long came up with a terrible feeling I never expressed respect to the blog owner for those techniques. These boys ended up for this reason very interested to read through all of them and have now in truth been making the most of those things. We appreciate you indeed being really accommodating and then for utilizing this kind of incredibly good areas millions of individuals are really wanting to be informed on. Our own sincere apologies for not expressing appreciation to you sooner.

louboutin shoes

I simply had to thank you so much once more. I'm not certain the things I would have gone through in the absence of these points shown by you concerning that concern. Previously it was the fearsome condition for me, but looking at a specialised style you handled the issue took me to jump with joy. Extremely happy for this guidance and then trust you are aware of a powerful job you're providing teaching people today with the aid of your web page. I know that you haven't got to know all of us.

golden goose

Thanks for each of your labor on this blog. My aunt really likes engaging in investigation and it's easy to see why. My spouse and i hear all of the lively way you make vital ideas by means of the web blog and even inspire contribution from others on this article plus our favorite princess is really studying a great deal. Take pleasure in the rest of the year. You are conducting a great job.

birkin bag

I wanted to put you one little note in order to say thank you as before for those superb thoughts you've discussed here. This is unbelievably open-handed with you to give openly what a number of people could have distributed as an e-book to generate some cash on their own, specifically since you might well have done it in the event you wanted. Those solutions also worked to provide a easy way to recognize that the rest have the identical keenness like my very own to know very much more when it comes to this problem. I know there are many more fun periods in the future for people who scan through your website.

Add new comment | arxic Drupal

My brother recommended I might like this web site. He was entirely right.
This post truly made my day. You can not imagine just
how much time I had spent for this information! Thanks!

supreme clothing

I want to express some thanks to the writer just for rescuing me from this predicament. Because of looking out throughout the world wide web and meeting advice which were not pleasant, I believed my entire life was well over. Being alive without the presence of strategies to the problems you have sorted out by means of the short post is a crucial case, and the kind which could have badly affected my career if I had not encountered your web blog. Your own natural talent and kindness in dealing with all things was very helpful. I'm not sure what I would've done if I had not encountered such a thing like this. It's possible to at this moment look forward to my future. Thanks a lot so much for the skilled and amazing guide. I won't think twice to propose the sites to any person who needs and wants recommendations on this problem.

kyrie 5

I want to show some thanks to the writer just for bailing me out of this type of instance. Just after searching through the the net and getting advice that were not pleasant, I figured my entire life was well over. Existing devoid of the strategies to the problems you've sorted out by way of your blog post is a crucial case, as well as those that would have in a wrong way damaged my career if I hadn't come across your web site. That competence and kindness in playing with all things was helpful. I don't know what I would have done if I had not come across such a stuff like this. I'm able to at this moment look forward to my future. Thanks so much for the professional and effective help. I won't hesitate to refer your site to any person who should receive direction about this subject.

vans

I wish to express some thanks to the writer just for bailing me out of this particular crisis. Because of exploring throughout the search engines and obtaining ways that were not pleasant, I figured my entire life was done. Being alive devoid of the strategies to the issues you have solved all through your website is a crucial case, as well as ones that would have badly damaged my career if I had not encountered your web blog. Your main ability and kindness in playing with the whole thing was very helpful. I'm not sure what I would've done if I had not come upon such a solution like this. I can also now look forward to my future. Thanks very much for the reliable and result oriented guide. I won't think twice to refer your web blog to anyone who wants and needs tips about this subject.

Add new comment | arxic Drupal

You're so interesting! I do not think I've truly read through something like this before.
So nice to find another person with some genuine thoughts on this issue.
Seriously.. many thanks for starting this up. This site is something that's
needed on the internet, someone with a little originality!

supreme clothing

I happen to be commenting to make you know what a notable discovery my child undergone using yuor web blog. She figured out some issues, not to mention what it is like to have an amazing helping nature to make the others smoothly master specified extremely tough issues. You undoubtedly surpassed her expectations. Thank you for distributing such valuable, safe, educational and fun thoughts on this topic to Tanya.

timberland boots

I precisely had to appreciate you once again. I'm not certain the things that I would've sorted out in the absence of the tactics revealed by you on such field. It previously was a very alarming condition in my circumstances, but taking note of the specialized mode you treated it made me to cry with happiness. Extremely grateful for this support and hope that you really know what a powerful job you are always undertaking instructing others via a blog. More than likely you have never encountered any of us.

Add new comment | arxic Drupal

I'm really inspired together with your writing abilities as neatly as with the format on your blog.
Is this a paid subject matter or did you modify it yourself?
Either way stay up the nice quality writing,
it's uncommon to see a nice blog like this one today..

lebron 16

I wish to show some appreciation to this writer for bailing me out of this type of challenge. Just after browsing throughout the world-wide-web and getting proposals that were not powerful, I thought my entire life was over. Existing without the presence of answers to the difficulties you've solved all through this blog post is a critical case, as well as the ones which might have negatively damaged my entire career if I hadn't come across the website. Your main skills and kindness in maneuvering a lot of stuff was excellent. I don't know what I would've done if I had not encountered such a point like this. I can now look ahead to my future. Thanks so much for your reliable and result oriented help. I will not think twice to endorse your blog post to anybody who needs and wants guidelines about this problem.

Add new comment | arxic Drupal

Hey just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Ie.
I'm not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I'd post to let you know.
The design look great though! Hope you get the problem fixed soon. Thanks

off white nike

I am glad for writing to make you be aware of of the exceptional experience my daughter developed reading through yuor web blog. She picked up some things, most notably what it is like to have an awesome coaching nature to make men and women completely fully understand various impossible subject matter. You really exceeded people's expected results. Many thanks for displaying these important, dependable, educational and in addition easy tips on that topic to Mary.

Add new comment | arxic Drupal

Excellent post. I used to be checking constantly this weblog and I'm impressed!
Extremely useful information specifically the closing section :) I care for such info
much. I used to be looking for this particular info for a very lengthy time.

Thank you and best of luck.

balenciaga shoes

I together with my buddies appeared to be reading the good guidelines located on the blog and then immediately came up with an awful suspicion I never expressed respect to the site owner for those techniques. All of the women are already consequently glad to read all of them and have now in actuality been loving these things. We appreciate you getting considerably accommodating and also for choosing such superb themes most people are really desperate to learn about. Our own sincere apologies for not saying thanks to you sooner.

смотреть в хорошем качестве hd 720 фантастику

Приветствую всех! интересный у вас сайт!
Нашел топ базу кино: <a href=http://inspacefilm.ru/>мультфильмы 2018 смотреть бесплатно в хорошем полностью</a>
Здесь: <a href=http://inspacefilm.ru/semeynyy/>семейный фильм онлайн бесплатно в хорошем качестве</a> фильмы 2018 семейные список 2019
Тут: вечность сериал смотреть онлайн бесплатно в хорошем http://inspacefilm.ru/serialy/ список 2018
Тут: лучшие триллеры 2018 смотреть онлайн бесплатно http://inspacefilm.ru/triller/ список 2018
Тут: http://inspacefilm.ru/10210-gildiya-prodyuserov-ssha-predstavila-svoih-n... <b> Гильдия продюсеров США представила своих номинантов (фильмы) </b>
Тут: http://inspacefilm.ru/13205-suprugi-morgan-v-begah-did-you-hear-about-th...

Add new comment | arxic Drupal

Write more, thats all I have to say. Literally, it seems as though you
relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos
to your site when you could be giving us something enlightening to read?

Add new comment | arxic Drupal

Thanks for your marvelous posting! I certainly enjoyed reading it, you happen to be a great author.I will be
sure to bookmark your blog and will often come back in the foreseeable future.
I want to encourage continue your great job, have a nice holiday weekend!

Add new comment | arxic Drupal

Everything is very open with a really clear clarification of the challenges.
It was really informative. Your website is very helpful.

Thanks for sharing!

Add new comment | arxic Drupal

Does your website have a contact page? I'm having a tough time locating it but, I'd
like to shoot you an email. I've got some ideas for your blog
you might be interested in hearing. Either way, great website and I
look forward to seeing it improve over time.

Add new comment | arxic Drupal

We stumbled over here different web page and thought I might as
well check things out. I like what I see so now i'm following you.
Look forward to exploring your web page for a second time.

Pages

Add new comment