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

supreme clothing

Thank you a lot for giving everyone an extremely remarkable opportunity to read from this site. It can be so cool and as well , jam-packed with fun for me personally and my office friends to search the blog no less than 3 times in a week to learn the new secrets you will have. Not to mention, I'm usually impressed considering the powerful creative concepts served by you. Certain 1 areas in this posting are honestly the most impressive I've ever had.

Add new comment | arxic Drupal

Hey there! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative in a community
in the same niche. Your blog provided us valuable information to work on. You
have done a marvellous job!

kyrie 5

I actually wanted to send a message to be able to say thanks to you for some of the wonderful secrets you are posting on this site. My particularly long internet search has at the end been paid with excellent information to share with my two friends. I would assert that many of us website visitors actually are quite fortunate to dwell in a great network with many marvellous people with great tricks. I feel very much privileged to have encountered the web site and look forward to plenty of more brilliant minutes reading here. Thanks a lot once more for a lot of things.

supreme clothing

Thank you so much for providing individuals with an extraordinarily splendid opportunity to discover important secrets from here. It's always so ideal plus packed with amusement for me personally and my office fellow workers to visit the blog not less than three times a week to learn the fresh secrets you have got. And of course, I am also always fulfilled with your remarkable techniques you serve. Certain 2 ideas in this posting are basically the finest we've ever had.

nike air max95

I precisely had to thank you very much once again. I am not sure the things that I would have accomplished without the entire concepts shared by you about this area of interest. It was before a real scary matter in my circumstances, but encountering this specialized technique you treated that made me to cry with happiness. I will be thankful for this service and even sincerely hope you really know what a great job you were accomplishing instructing others through the use of your webblog. Most probably you haven't got to know all of us.

Add new comment | arxic Drupal

Good post. I learn something totally new and challenging on sites I stumbleupon on a daily
basis. It's always exciting to read through content from other writers and use
something from their sites.

Add new comment | arxic Drupal

Its like you read my mind! You seem to know a lot about this,
like you wrote the book in it or something. I think that you can do with a few
pics to drive the message home a little bit, but other than that, this is great blog.

A fantastic read. I will definitely be back.

nike air max 2017

Youre so cool! I dont suppose Ive read something like this before. So nice to seek out somebody with some original ideas on this subject. realy thank you for starting this up. this web site is one thing that's needed on the internet, someone with somewhat originality. useful job for bringing something new to the internet!

yeezy shoes

It抯 onerous to search out knowledgeable individuals on this topic, however you sound like you already know what you抮e speaking about! Thanks

supreme

Spot on with this write-up, I really think this web site wants much more consideration. I抣l probably be again to read far more, thanks for that info.

kd 12 shoes

I抦 impressed, I have to say. Actually not often do I encounter a blog that抯 each educative and entertaining, and let me inform you, you have got hit the nail on the head. Your idea is outstanding; the problem is something that not enough persons are speaking intelligently about. I am very pleased that I stumbled throughout this in my search for one thing relating to this.

Add new comment | arxic Drupal

This is a good tip particularly to those new to the blogosphere.
Brief but very precise information… Many thanks for sharing this one.
A must read post!

longchamp

Aw, this was a very nice post. In concept I want to put in writing like this moreover ?taking time and actual effort to make an excellent article?however what can I say?I procrastinate alot and by no means appear to get one thing done.

Add new comment | arxic Drupal

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

chrome hearts

I want to show my thanks to this writer just for bailing me out of this particular trouble. As a result of checking through the world wide web and obtaining tricks which are not powerful, I believed my entire life was over. Living devoid of the strategies to the issues you've sorted out by way of your good review is a crucial case, and the kind that would have negatively damaged my career if I had not encountered the website. Your main capability and kindness in dealing with all things was priceless. I'm not sure what I would have done if I had not come upon such a thing like this. It's possible to at this moment look forward to my future. Thanks a lot so much for your reliable and effective guide. I won't hesitate to refer the website to anyone who should get guidance on this subject matter.

supreme outlet

I precisely had to thank you so much again. I am not sure the things that I would have carried out in the absence of these hints contributed by you on that situation. This has been the horrifying setting for me personally, however , viewing the very skilled style you solved it made me to leap over delight. I am just thankful for the help and as well , expect you find out what an amazing job you have been getting into training others through a site. Probably you've never met all of us.

Add new comment | arxic Drupal

Have you ever considered publishing an e-book or guest authoring on other sites?
I have a blog centered on the same ideas you discuss and would love to have you
share some stories/information. I know my readers would value your work.
If you are even remotely interested, feel free to send
me an email.

moncler jackets

I am glad for writing to make you be aware of what a exceptional encounter my wife's daughter gained going through your site. She figured out a wide variety of details, which included what it is like to have an incredible giving nature to let men and women clearly completely grasp specified very confusing subject matter. You actually exceeded people's expectations. Many thanks for presenting those invaluable, healthy, informative as well as cool tips about the topic to Kate.

supreme clothing

I enjoy you because of your whole labor on this web page. My niece loves carrying out investigations and it is easy to see why. We learn all about the compelling means you offer functional strategies by means of your web site and as well as strongly encourage participation from the others on this subject matter while our simple princess is truly becoming educated a great deal. Enjoy the rest of the new year. You're the one conducting a pretty cool job.

calvin klein underwear

I want to show my thanks to you for bailing me out of this particular condition. Right after exploring through the world-wide-web and meeting strategies which are not powerful, I was thinking my life was well over. Being alive without the solutions to the issues you have resolved as a result of this blog post is a serious case, as well as those which could have adversely damaged my entire career if I had not noticed your web blog. Your skills and kindness in touching all areas was excellent. I am not sure what I would have done if I had not come upon such a solution like this. I'm able to now look forward to my future. Thanks for your time so much for the impressive and amazing help. I will not be reluctant to recommend your web page to anyone who would need guidance on this problem.

chrome hearts store

Thank you for each of your work on this site. My mum really likes doing internet research and it's simple to grasp why. Most of us notice all concerning the powerful form you convey good suggestions on this web blog and in addition increase response from website visitors about this subject so our own daughter is in fact learning a whole lot. Have fun with the remaining portion of the year. You're the one performing a great job.

hermes handbags

I simply wished to say thanks yet again. I do not know what I might have implemented in the absence of the entire basics discussed by you over my field. It has been a very traumatic concern for me personally, nevertheless taking note of this skilled tactic you processed it made me to weep over delight. Now i'm thankful for the information and as well , have high hopes you comprehend what an amazing job you have been doing instructing many people using a blog. Probably you've never met all of us.

Add new comment | arxic Drupal

Woah! I'm really enjoying the template/theme of this website.
It's simple, yet effective. A lot of times it's very difficult to get that
"perfect balance" between superb usability and visual appearance.
I must say that you've done a amazing job with this.

Additionally, the blog loads extremely quick for me on Internet explorer.
Excellent Blog!

christian louboutin shoes

My spouse and i got glad when Emmanuel managed to finish off his researching through the entire precious recommendations he received using your site. It is now and again perplexing to simply happen to be giving out instructions men and women have been selling. We really keep in mind we now have the writer to give thanks to for that. These illustrations you made, the simple site navigation, the friendships your site help to instill - it's most excellent, and it's helping our son and our family believe that this situation is pleasurable, which is quite essential. Many thanks for the whole lot!

Add new comment | arxic Drupal

Oh my goodness! Impressive article dude! Many thanks, However I am experiencing difficulties with your RSS.
I don't know the reason why I am unable to subscribe to it.

Is there anybody else having similar RSS problems?
Anyone who knows the solution can you kindly respond?

Thanks!!

cheap jordans

I'm writing to let you be aware of of the excellent encounter my cousin's daughter found studying the blog. She discovered numerous details, including what it is like to have an ideal helping character to make other individuals effortlessly learn specific extremely tough issues. You truly exceeded our desires. Thanks for coming up with such invaluable, safe, revealing and in addition easy guidance on this topic to Sandra.

air jordan shoes

I actually wanted to write down a quick message to be able to express gratitude to you for those great secrets you are placing here. My time consuming internet look up has at the end of the day been honored with beneficial concept to exchange with my family members. I would declare that many of us site visitors actually are truly fortunate to dwell in a perfect network with many brilliant people with interesting plans. I feel rather lucky to have encountered your website and look forward to plenty of more pleasurable times reading here. Thanks a lot once again for all the details.

kate spade outlet

I actually wanted to type a brief comment to say thanks to you for the unique recommendations you are giving out here. My time consuming internet look up has now been recognized with wonderful facts and techniques to talk about with my friends and family. I 'd declare that most of us visitors actually are undeniably blessed to live in a decent network with so many brilliant people with valuable suggestions. I feel truly privileged to have encountered your entire web page and look forward to really more awesome moments reading here. Thanks once again for all the details.

off-white

I as well as my friends were actually reading the best tips and tricks found on your web blog while before long developed an awful feeling I had not expressed respect to the website owner for those tips. The young men became as a result joyful to read them and already have extremely been enjoying those things. We appreciate you truly being really accommodating and then for making a choice on this kind of superior subject areas most people are really desperate to understand about. My personal sincere apologies for not expressing appreciation to you sooner.

Add new comment | arxic Drupal

I was curious if you ever thought of changing the layout of your blog?
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 2 images.
Maybe you could space it out better?

yeezy shoes

I intended to post you the tiny word to finally give thanks as before relating to the amazing basics you've discussed here. It is so pretty open-handed of you to give unhampered all that a few people could possibly have advertised as an e book to end up making some bucks on their own, mostly since you might have done it if you wanted. Those ideas likewise worked to be the fantastic way to be sure that the rest have similar keenness just like my personal own to know the truth great deal more in terms of this problem. I know there are a lot more pleasant situations up front for folks who check out your blog.

Add new comment | arxic Drupal

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.
I think that you can do with some pics to drive the message home a little bit, but instead of that,
this is magnificent blog. An excellent read. I will certainly be back.

moncler

I'm commenting to make you know what a remarkable discovery our girl developed checking yuor web blog. She noticed a lot of things, with the inclusion of how it is like to have an amazing helping heart to let certain people clearly grasp some advanced subject matter. You undoubtedly exceeded my expected results. I appreciate you for providing those invaluable, safe, explanatory and even cool guidance on that topic to Janet.

Pages

Add new comment