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

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.

nike air max 2018

I wanted to send a note to say thanks to you for these fabulous strategies you are writing on this website. My particularly long internet research has now been compensated with high-quality content to exchange with my family members. I 'd believe that most of us readers actually are unquestionably lucky to live in a great place with very many brilliant people with good tips. I feel extremely privileged to have discovered your entire web pages and look forward to so many more entertaining minutes reading here. Thank you once more for a lot of things.

Add new comment | arxic Drupal

excellent issues altogether, you simply won a new reader.
What may you suggest about your publish that you simply made a few days ago?
Any sure?

longchamp

I needed to put you a tiny remark just to thank you so much once again considering the amazing secrets you have shared on this page. This is so remarkably generous with people like you in giving publicly precisely what a number of people would have sold as an electronic book to earn some profit for themselves, primarily given that you might have tried it if you ever wanted. Those strategies likewise worked to be the good way to recognize that other individuals have similar passion like my very own to find out more and more in regard to this matter. Certainly there are millions of more enjoyable instances ahead for people who see your blog.

Add new comment | arxic Drupal

Excellent post. I was checking continuously this blog and I'm
impressed! Very useful info particularly the last part :) I care for such information much.
I was seeking this particular information for a long
time. Thank you and good luck.

adidas nmd

I must express some appreciation to the writer for rescuing me from this particular instance. Because of checking throughout the search engines and coming across ideas which are not powerful, I assumed my life was well over. Being alive devoid of the strategies to the difficulties you have solved as a result of this blog post is a serious case, and the kind that might have badly affected my entire career if I had not discovered your blog. Your own personal skills and kindness in maneuvering a lot of stuff was valuable. I don't know what I would have done if I hadn't come across such a solution like this. I can also now look forward to my future. Thanks for your time very much for your reliable and effective guide. I won't be reluctant to recommend the blog to anyone who needs to have guidance on this problem.

Add new comment | arxic Drupal

I absolutely love your blog and find almost all of your post's to be precisely what I'm
looking for. Do you offer guest writers to write content in your case?

I wouldn't mind publishing a post or elaborating on many
of the subjects you write related to here. Again, awesome web log!

supreme clothing

I not to mention my guys were studying the great information located on your web site and so all of a sudden came up with a terrible suspicion I had not thanked the blog owner for those tips. The guys were definitely so thrilled to read through all of them and now have really been tapping into these things. Thanks for actually being very helpful and also for making a choice on some extraordinary subjects most people are really desirous to be informed on. Our sincere apologies for not expressing appreciation to earlier.

louboutin shoes

I happen to be commenting to make you understand what a incredible encounter my cousin's daughter went through reading through your blog. She mastered a lot of pieces, not to mention what it is like to possess an ideal coaching mood to make the others just thoroughly grasp various impossible things. You actually did more than her expected results. Many thanks for giving the powerful, healthy, explanatory and unique thoughts on that topic to Sandra.

Add new comment | arxic Drupal

Hey there! This is kind of off topic but I need some help from an established blog.
Is it difficult to set up your own blog? I'm not very techincal
but I can figure things out pretty quick. I'm thinking about creating my own but
I'm not sure where to start. Do you have
any tips or suggestions? Thank you

Harizzma Music

<b>
Добрый день!
Меня зовут Артем, я живу в России в городе Сочи.
Я музыкант, занимаюсь музыкой - исполняю рэп.
Послушай мой новый трек и скажи пожалуйста свое мнение!
Вот моя страница Instagram - подписывайся на меня - я буду рад тебе!

https://www.instagram.com/kavabanga__kos/

</b>

viagra buy online cheap

where buy viagra online <a href="http://goldviaqraonline.com/#">canadian pharmacy no prescription </a> extended breastfeeding for weight loss <a href=http://goldviaqraonline.com/#>asthma preventer inhaler purple </a> cialis generic reviews
mail order online pharmacy <a href="http://cialisforsale2020.net/#">generic cialis us </a> fat burning shot ingredients <a href=http://cialisforsale2020.net/#>cialis generic form </a> buy levitra generic

HenrySague

sildenafil citrate что это read news sites <a href="http://xanaxbarse.net/#">cheap Xanax</a> viagra generic online viagra generic url <a href=http://xanaxbarse.net/#>xanax bars for sale us </a> read naija news online
cheap viagra montreal read news in japanese <a href="https://genericviagrarxpills.com/#">https://genericviagrarxpills.com/</a> generic online cialis <a href=https://genericviagrarxpills.com/#>buy viagra luton </a> read news about zambia

Pages

Add new comment