Thursday 12 July 2012

Installing node.js on Drupal


The node.js module (www.drupal.org/project/nodejs) is a great way to get node.js working with your Drupal installation. Although the README.txt file is verbose, I had problems getting everything working. Below are instructions that I believe are a little clearer.
  1. Make sure your system has the programs that node.js needs
    sudo apt-get install build-essential git curl openssl libssl-dev -y
  2. Install node.js
    mkdir -p ~/local/src
    cd ~/local/src
    git clone https://github.com/joyent/node.git
    cd node
    ./configure
    1. If openssl is showing as not found:
      sudo apt-get install pkg-config
      pkg-config openssl --cflags --libs
      ./configure
    2. Now you should run make and make install
      make && make install
  3. Run
    sudo curl http://npmjs.org/install.sh | sh
    cd /path/to/nodejs/module
    npm install
    1. If npm install give you multiple errors about the connect or express modules then you probably installed an unstable version on node.js. Refer the the Problems section below to get this fixed!
  4. Enable the Nodejs Integration module from your drupal site or using drush en nodejs
    1. You should also enable the Nodejs Config module for clearer config options (drush cc all when enabled).
    2. Host, by default, is set to localhost. If you are not working locally set it to your sites IP address.
  5. In your nodejs module directory, copy nodejs.config.js.example to nodejs.config.js
    1. cp nodejs.config.js.example nodejs.config.js.
    2. If you used the Nodejs Config module, overwrite nodejs.config.js with the output it generated for you.
  6. Run the command:
    node server.js
If you don't get an error here you are done! The output I received was "info - socket.io started" so I know the server was running.

Problems

If you tried to run npm install and receive multiple error messages then you probably have an unstable version. Visit http://nodejs.org/#download and download the latest stable version. Unzip and untar it in ~/local/src/ (tar -zxvf [filename]). remove your previous node directory and rename your new directory "node".
./configure
make && make install
Now repeat step 3 above. If you still are getting errors with connect and/or express, download the suggested version of each package:
The error message will say something like requires connect@'>=1.5.7' this means you should run the command
npm install connect@1.5.7
If you get an error here saying that your version of node is not compatible, then you still have an unstable version!

No comments:

Post a Comment