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

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.

Add new comment | arxic Drupal

Howdy would you mind stating which blog platform you're using?
I'm planning to start my own blog soon but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

The reason I ask is because your design seems different then most blogs and I'm looking for something unique.
P.S Sorry for getting off-topic but I had to ask!

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 throw
away your intelligence on just posting videos to your site when you could be giving us something enlightening to read?

Add new comment | arxic Drupal

This is very interesting, You're a very skilled blogger.
I have joined your rss feed and look forward to seeking more of your wonderful post.
Also, I've shared your site in my social networks!

Add new comment | arxic Drupal

You actually make it seem so easy with your presentation but I find this matter to be actually something which I
think I would never understand. It seems too complicated and very broad for me.
I am looking forward for your next post, I'll try to get
the hang of it!

Add new comment | arxic Drupal

Woah! I'm really digging the template/theme of this website.

It's simple, yet effective. A lot of times
it's hard to get that "perfect balance" between superb usability and visual appeal.
I must say you have done a fantastic job with this.
Also, the blog loads super fast for me on Chrome.

Outstanding Blog!

Add new comment | arxic Drupal

Excellent beat ! I would like to apprentice while you amend
your website, how could i subscribe for a blog web site?
The account helped me a acceptable deal. I had been tiny bit acquainted of this
your broadcast provided bright clear concept

как домашними средствами усилить потенцию

Привет всем участникам форума! прикольный у вас сайт!
Нашел интересную инфу: <b> как быстро похудеть за день </b> <a href=http://sportmanlife.ru/>http://sportmanlife.ru/</a>
Здесь: как быстро накачать нижний пресс http://sportmanlife.ru/kak-nakachat-press/
Тут: <a href=http://sportmanlife.ru/52-rasputnica-rasputnica-naturalnye-innovacionnye...капли для возбуждения женщин в аптеках название</a> сколько стоят капли распутница
Тут: <a href=http://sportmanlife.ru/46-krem-titan-gel-uvelichenie-chlena-i-usilenie-p...увеличение члена в домашних условиях</a> titan gel сайт

how to make profit

Hello, tired of sitting with no money?
I was just a poor student, and now i make 1100$ - 1400$ every day here: http://9binaryoptions.net/uploads/reviews/passive-business-ideas.htm - make real money online
It works! Checked. Good luck to all!

This online work from home is available in all countries! These articles will help you:
<a href=http://9binaryoptions.net/uploads/reviews/best-way-to-earn-money-from-ho... best way to earn money from home </a>
<b> Бинарные опционы мнение </b> <a href=http://9binaryoptions.net/ru> Бинарные опционы мнение </a>
Start Now!

Add new comment | arxic Drupal

I'm not sure exactly why but this blog is loading very slow for me.

Is anyone else having this problem or is it a issue on my end?
I'll check back later and see if the problem still exists.

смотреть кино лучший триллер

Всем привет! прикольный у вас сайт!
Нашел прикольную базу кино: <a href=http://kinoserialtv.net/>лучшие русские сериалы детективы смотреть онлайн</a>
Тут: фантастика 2018 смотреть бесплатно в хорошем качестве http://kinoserialtv.net/fantastika/ рейтинг 2018
Здесь: <a href=http://kinoserialtv.net/komediya/>лучшие новые комедии смотреть</a> бесплатные лучшие комедии 2019 года рейтинг 2018
Тут: <a href=http://kinoserialtv.net/melodrama/>смотреть лучшие русские мелодрамы новинки</a> фильмы 2019 смотреть хорошем бесплатно онлайн мелодрамы рейтинг 2018
Здесь: http://kinoserialtv.net/2995-moy-mir-benim-dunyam-2013.html <b> Смотреть Мой мир / Benim Dunyam (2013) онлайн бесплатно </b>
Тут: http://kinoserialtv.net/249-kolin-ford-o-seriale-pod-kupolom.html

Pages

Add new comment