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

moncler

I simply wished to say thanks yet again. I'm not certain what I could possibly have followed without the type of tactics discussed by you about such subject. Entirely was a very frustrating scenario in my position, nevertheless spending time with the specialized approach you handled that took me to jump over gladness. Now i'm happier for your support and as well , hope that you find out what a great job you're doing teaching people via your blog post. I'm certain you haven't encountered all of us.

salvatore ferragamo belt

Thank you a lot for giving everyone remarkably memorable opportunity to check tips from this site. It is always so beneficial and jam-packed with a great time for me personally and my office fellow workers to search your web site not less than 3 times per week to see the new things you will have. Of course, I'm so at all times amazed for the splendid concepts you give. Selected two areas on this page are certainly the simplest I have had.

Add new comment | arxic Drupal

Admiring the hard work you put into your site and in depth information you offer.

It's good to come across a blog every once in a while that isn't the same
outdated rehashed material. Excellent read! I've bookmarked
your site and I'm adding your RSS feeds to my Google account.

nike air vapormax

I would like to point out my respect for your kindness for individuals who have the need for guidance on the subject matter. Your personal commitment to getting the message all around has been incredibly beneficial and have surely encouraged employees like me to achieve their endeavors. Your own insightful suggestions denotes so much a person like me and even more to my office workers. Many thanks; from everyone of us.

Add new comment | arxic Drupal

This design is steller! You most certainly
know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost...HaHa!) Fantastic job.

I really enjoyed what you had to say, and more than that, how you presented it.

Too cool!

yeezy shoes

Needed to send you one bit of observation to finally thank you yet again relating to the superb guidelines you have provided on this page. It's really pretty generous of you to give unreservedly precisely what a number of us could have offered for an ebook in order to make some money for themselves, mostly now that you could have done it if you ever considered necessary. Those strategies additionally served to be the good way to be aware that many people have similar eagerness the same as mine to know the truth lots more with regard to this issue. Certainly there are thousands of more pleasant opportunities ahead for individuals who take a look at your blog post.

Add new comment | arxic Drupal

Hey there! I understand this is kind of off-topic however I had to ask.

Does running a well-established blog like yours require a massive amount work?

I am completely new to operating a blog but I do write in my diary every day.
I'd like to start a blog so I can share my experience and views online.
Please let me know if you have any kind of suggestions or tips for brand new aspiring bloggers.

Thankyou!

yeezy shoes

I would like to get across my respect for your kindness for men and women that must have assistance with in this area. Your very own dedication to getting the message all-around had been definitely good and has specifically enabled men and women like me to realize their endeavors. Your amazing invaluable useful information can mean much to me and somewhat more to my mates. With thanks; from each one of us.

moncler outlet

I simply wanted to send a small message in order to say thanks to you for all of the amazing tips and tricks you are giving out on this site. My time consuming internet look up has finally been paid with pleasant facts and strategies to go over with my pals. I would say that most of us website visitors are extremely lucky to exist in a superb network with so many outstanding individuals with very helpful advice. I feel pretty grateful to have seen the webpage and look forward to some more amazing minutes reading here. Thanks a lot once again for everything.

converse outlet

I intended to draft you one little bit of note just to give thanks once again on your great knowledge you have provided on this website. It was really incredibly generous with you giving unreservedly what a lot of folks could have offered as an electronic book to help make some bucks for their own end, specifically now that you could possibly have done it if you desired. These smart ideas additionally acted to become a great way to know that the rest have a similar desire similar to my own to figure out a lot more related to this problem. I'm sure there are thousands of more pleasant sessions up front for those who read through your website.

Add new comment | arxic Drupal

Wonderful blog! I found it while surfing around
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!
Appreciate it

nhl jerseys

A powerful share, I simply given this onto a colleague who was doing slightly analysis on this. And he the truth is bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If doable, as you turn out to be experience, would you thoughts updating your blog with extra details? It's highly helpful for me. Huge thumb up for this weblog submit!

balenciaga

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

Add new comment | arxic Drupal

I think this is among the most significant information for me.

And i am glad reading your article. But want to remark on some general things, The web site style is great, the articles is really great
: D. Good job, cheers

Add new comment | arxic Drupal

Hey exceptional website! Does running a blog like
this require a large amount of work? I've no knowledge of coding but I had been hoping to start my own blog in the near future.
Anyways, should you have any recommendations or tips for new blog owners please share.
I understand this is off topic but I just needed to ask.
Appreciate it!

kyrie 5

There are some interesting deadlines on this article but I don抰 know if I see all of them center to heart. There may be some validity but I will take hold opinion until I look into it further. Good article , thanks and we wish more! Added to FeedBurner as effectively

Add new comment | arxic Drupal

No matter if some one searches for his necessary thing,
therefore he/she wants to be available that in detail, therefore that thing is maintained over
here.

moncler jackets

After study just a few of the weblog posts in your web site now, and I really like your manner of blogging. I bookmarked it to my bookmark website list and will be checking again soon. Pls try my web page as well and let me know what you think.

Add new comment | arxic Drupal

What's up to every one, for the reason that I am truly keen of reading this website's post to be updated regularly.
It consists of good material.

balenciaga

Youre so cool! I dont suppose Ive read anything like this before. So good to search out any person with some authentic ideas on this subject. realy thank you for starting this up. this web site is something that's wanted on the web, someone with a little originality. helpful job for bringing something new to the internet!

supreme shirts

The next time I read a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, however I truly thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about something that you could possibly fix when you werent too busy searching for attention.

nike foamposite

I would like to point out my appreciation for your kindness in support of people who require assistance with the content. Your very own dedication to getting the solution throughout had become exceptionally beneficial and has made guys just like me to reach their pursuits. Your amazing important instruction can mean a whole lot to me and still more to my peers. Many thanks; from everyone of us.

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.

Pages

Add new comment