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 boost

An impressive share, I just given this onto a colleague who was doing a little bit evaluation on this. And he actually bought me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If possible, as you turn out to be experience, would you thoughts updating your weblog with extra details? It's extremely helpful for me. Big thumb up for this weblog put up!

смотреть в хорошем качестве 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

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

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

Add new comment | arxic Drupal

I've been browsing on-line greater than three hours
as of late, but I never discovered any interesting article
like yours. It is pretty price enough for me. In my view, if
all site owners and bloggers made just right content as you did, the web will likely be much more helpful than ever before.

Add new comment | arxic Drupal

An interesting discussion is definitely worth comment.
I do believe that you should write more about this issue, it may not be a
taboo matter but generally people don't talk about these issues.
To the next! Best wishes!!

Add new comment | arxic Drupal

Have yoou ever thought abkut adding a little bit more than just your articles?
I mean, what you say is important and everything.
Nevertheless just imagine if you added some gret graphics or video clips to give your posts more, "pop"!
Your content is excellent but with pics aand videos, this site could certainly be one
oof the very best in its field. Awesome blog!

Add new comment | arxic Drupal

Its like you learn my mind! You seem to know a lot
about this, such as you wrote the guide in it or something.
I think that you just can do with a few percent to drive the message home a little bit, but instead of that, that is magnificent blog.
An excellent read. I'll certainly be back.

Add new comment | arxic Drupal

I got this site from my buddy who shared with me concerning this web site and at the moment this time I am
browsing this web site and reading very informative content at
this time.

Add new comment | arxic Drupal

When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get three e-mails with the same comment.
Is there any way you can remove people from that service?

Bless you!

Add new comment | arxic Drupal

I believe that is among the such a lot important information for me.
And i'm satisfied studying your article. However should statement on few common things, The web site
style is perfect, the articles is really nice
: D. Excellent task, cheers

Add new comment | arxic Drupal

I love your blog.. very nice colors & theme. Did you design this website yourself or
did you hire someone to do it for you? Plz answer back as I'm looking
to create my own blog and would like to find out where u
got this from. thanks a lot

Pages

Add new comment