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

yeezy shoes

I together with my guys were found to be checking the great tips and tricks found on your website and so all of a sudden developed a terrible feeling I had not expressed respect to the website owner for those techniques. Those boys were for this reason happy to read through them and already have seriously been taking pleasure in these things. Thanks for simply being so considerate and then for getting varieties of terrific subjects most people are really desperate to know about. Our honest apologies for not expressing gratitude to you earlier.

yeezy shoes

I and my friends were going through the best items found on your web page and so suddenly came up with an awful feeling I had not expressed respect to the site owner for those strategies. The young men became for this reason glad to read through them and have without a doubt been using them. Thank you for being simply thoughtful and then for opting for this kind of superb topics millions of individuals are really wanting to understand about. My personal sincere apologies for not saying thanks to earlier.

salvatore ferragamo belt

I wanted to jot down a quick comment to be able to express gratitude to you for some of the wonderful tips and tricks you are placing at this site. My time consuming internet research has at the end been recognized with reasonable facts and techniques to share with my family members. I would express that most of us site visitors actually are unquestionably fortunate to live in a fantastic website with many perfect people with interesting strategies. I feel very much happy to have discovered your entire website page and look forward to tons of more pleasurable moments reading here. Thank you once more for all the details.

golden goose

I must show my appreciation to the writer for rescuing me from this incident. Just after looking through the the web and seeing recommendations which were not helpful, I figured my entire life was gone. Being alive without the presence of answers to the difficulties you've fixed through your entire short article is a serious case, as well as those that might have badly damaged my career if I had not noticed the blog. Your good skills and kindness in playing with all the stuff was vital. I am not sure what I would have done if I had not come upon such a thing like this. I am able to at this time look forward to my future. Thank you very much for your skilled and effective guide. I will not hesitate to endorse your web sites to any person who would like guidelines about this issue.

nike max

I want to express appreciation to you for rescuing me from such a difficulty. After looking out throughout the world wide web and finding advice which are not beneficial, I assumed my life was well over. Existing without the presence of approaches to the problems you have resolved as a result of your article content is a critical case, as well as ones which might have in a wrong way affected my career if I had not encountered the blog. The understanding and kindness in maneuvering all areas was excellent. I don't know what I would've done if I had not come across such a point like this. I can also now look forward to my future. Thank you so much for your high quality and amazing guide. I will not hesitate to endorse your web sites to anybody who needs to have care on this matter.

yeezy boost 350 v2

I must show appreciation to you just for rescuing me from this difficulty. After scouting through the world wide web and finding tips which are not helpful, I believed my life was gone. Being alive minus the strategies to the problems you've solved all through your article content is a serious case, and the kind which might have negatively affected my career if I had not discovered your web site. Your main ability and kindness in maneuvering all the things was priceless. I am not sure what I would've done if I had not come upon such a solution like this. I am able to at this point look ahead to my future. Thank you so much for this expert and effective guide. I won't hesitate to suggest your blog to any person who needs to have guide about this topic.

hermes birkin

I am commenting to make you understand what a notable discovery my wife's girl undergone checking your webblog. She picked up a wide variety of details, not to mention what it's like to possess an excellent helping nature to have a number of people with no trouble know a number of hard to do issues. You undoubtedly did more than readers' expectations. Thank you for rendering such useful, safe, edifying not to mention unique tips about your topic to Lizeth.

outlet golden goose

My wife and i were so contented when Jordan managed to do his web research by way of the precious recommendations he was given out of the web pages. It's not at all simplistic to just be giving freely methods the others might have been making money from. So we consider we need the website owner to thank for this. The most important illustrations you have made, the simple blog menu, the relationships you can make it easier to promote - it is many fantastic, and it's really assisting our son in addition to the family consider that the subject is entertaining, and that is seriously fundamental. Many thanks for the whole lot!

canada goose jacket

Thanks a lot for giving everyone an extremely special possiblity to read critical reviews from this website. It is always so pleasing and as well , full of fun for me personally and my office fellow workers to search your web site minimum three times per week to learn the newest tips you have. And definitely, we're certainly motivated considering the terrific things served by you. Selected 4 points on this page are certainly the most effective we have all had.

air max 270

I want to point out my admiration for your kindness for men who need assistance with your situation. Your special commitment to passing the solution all over appeared to be really important and have constantly allowed associates much like me to attain their pursuits. Your valuable instruction implies a whole lot to me and still more to my peers. With thanks; from all of us.

goyard handbags

This website online is mostly a walk-by way of for all of the info you wanted about this and didn抰 know who to ask. Glimpse right here, and you抣l definitely uncover it.

russell westbrook shoes

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

cheap jordans

I抦 impressed, I need to say. Actually hardly ever do I encounter a blog that抯 both educative and entertaining, and let me let you know, you might have hit the nail on the head. Your thought is excellent; the difficulty is something that not sufficient people are speaking intelligently about. I am very happy that I stumbled throughout this in my search for one thing regarding this.

kyrie irving shoes

Thanks for every one of your work on this blog. My mom takes pleasure in making time for investigation and it's really easy to see why. Most people hear all relating to the dynamic way you render vital strategies by means of this web blog and therefore welcome response from the others about this issue then our girl is now discovering so much. Take advantage of the rest of the new year. You're conducting a very good job.

yeezy shoes

My husband and i were really peaceful Raymond could round up his reports using the ideas he received out of the web site. It is now and again perplexing to simply be giving out facts that people may have been making money from. We really do know we have got the website owner to thank for this. The explanations you've made, the easy web site menu, the friendships your site help to create - it's many spectacular, and it is letting our son in addition to us know that this article is brilliant, which is certainly tremendously serious. Thanks for the whole thing!

golden goose

I truly wanted to jot down a simple word to be able to say thanks to you for all the magnificent instructions you are giving out at this site. My time intensive internet look up has now been rewarded with pleasant concept to write about with my contacts. I 'd repeat that we site visitors are very much blessed to live in a remarkable network with so many marvellous people with useful tips and hints. I feel pretty lucky to have encountered your web site and look forward to really more exciting moments reading here. Thanks once again for all the details.

lebron 16

I wish to express my love for your kind-heartedness giving support to those people that really need assistance with this content. Your personal commitment to passing the message all-around has been certainly powerful and has constantly made workers much like me to reach their endeavors. Your personal warm and helpful facts denotes a whole lot to me and even more to my office workers. Best wishes; from everyone of us.

nike epic react

I actually wanted to jot down a brief message so as to express gratitude to you for all the awesome guidelines you are posting on this website. My extended internet search has finally been compensated with awesome ideas to write about with my partners. I would claim that many of us visitors are definitely lucky to exist in a fine website with so many outstanding individuals with beneficial techniques. I feel pretty grateful to have seen your entire web page and look forward to really more exciting times reading here. Thanks once more for all the details.

air jordan

I'm just writing to make you understand what a brilliant discovery our child gained reading through your blog. She even learned lots of issues, including what it is like to have an ideal giving character to make the others with no trouble learn several complicated things. You undoubtedly surpassed people's desires. Thank you for offering these practical, safe, explanatory and in addition fun tips about this topic to Kate.

jordan 6

I have to show my appreciation for your kind-heartedness giving support to women who need help with that niche. Your personal dedication to getting the message all-around appeared to be definitely productive and have really encouraged women like me to reach their dreams. Your amazing insightful help and advice can mean a great deal a person like me and substantially more to my peers. Regards; from all of us.

vapormax

I would like to point out my affection for your kind-heartedness supporting folks who actually need help with your area. Your personal dedication to getting the message along had been really helpful and have specifically helped regular people much like me to reach their endeavors. Your informative help and advice can mean a great deal a person like me and especially to my mates. With thanks; from everyone of us.

nike huarache

I wish to point out my admiration for your kind-heartedness supporting those people that should have guidance on this particular content. Your personal commitment to getting the solution across has been wonderfully useful and has consistently allowed regular people just like me to attain their targets. Your entire insightful publication means a great deal a person like me and additionally to my mates. With thanks; from all of us.

supreme clothing

I am writing to let you know of the really good experience our girl developed reading your site. She learned a good number of pieces, most notably what it is like to have an awesome coaching style to let the rest clearly understand a variety of complicated subject areas. You undoubtedly exceeded people's expectations. Thanks for offering those powerful, healthy, informative and also fun tips about that topic to Janet.

fila shoes

My husband and i got so thankful that Peter managed to complete his homework through the entire precious recommendations he acquired using your weblog. It's not at all simplistic to simply continually be giving away tips and hints people today might have been making money from. We figure out we now have the blog owner to thank for that. The most important explanations you've made, the easy site menu, the friendships your site give support to promote - it is mostly astonishing, and it's helping our son and the family consider that the subject is cool, and that is unbelievably fundamental. Thank you for everything!

balenciaga sneakers

I simply wished to thank you so much all over again. I am not sure the things that I might have sorted out in the absence of the type of information revealed by you directly on such a topic. It was the alarming issue in my view, however , taking a look at your specialized tactic you treated that forced me to leap over gladness. I'm just thankful for this help and hope you know what a great job that you are getting into educating the others via your blog. I am sure you've never come across all of us.

balenciaga shoes

I intended to create you a very little remark to help say thank you yet again about the lovely strategies you've shown in this article. It's strangely generous with you to convey publicly what numerous people could have supplied as an e book to make some profit for their own end, chiefly considering that you might well have tried it in case you desired. Those secrets also acted as a fantastic way to be aware that other individuals have the identical dream just as my very own to realize more and more concerning this condition. I think there are a lot more enjoyable situations ahead for many who read your site.

christian louboutin shoes

Thanks for each of your hard work on this web page. Kate really likes carrying out investigations and it's really obvious why. Most people notice all regarding the dynamic way you present very important strategies on the website and therefore boost participation from other ones about this matter so my princess is undoubtedly understanding a lot. Enjoy the remaining portion of the new year. You're doing a great job.

Pages

Add new comment