How to install Node.js on WebFaction

Installing Node.js on WebFaction only takes a few minutes and a handful of commands.

1. In the WebFaction control panel, create a new “Custom app listening on port” application. Make a note of the port number it generates. You’ll also need to assign the app to a “website” and associate the website with a domain. For example purposes, let’s call the app “node” and let’s say you pointed it to “node.username.webfactional.com”.

2. SSH into your WebFaction server. Now we need to download the Node source.  First we’ll cd into the node folder that was generated for our app, create a new directory to hold the source files, and then download and extract the tarball.

cd ~/webapps/node
mkdir src
cd src
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1

3. The next few commands will take care of the installation. Note that Node will be installed in your HOME directory and that the Node binary will be located in ~/bin/.

./configure --jobs=1 --prefix=$HOME
make install

4. When installation is complete you can check to make sure that all is well and that Node is on your PATH by typing which node or node -v.

$ which node
~/bin/node

5. At this point Node is ready to go but there are a few other things you should install. Most importantly, the Node package manager npm.

curl http://npmjs.org/install.sh | sh

With npm installed, you may want to take the opportunity to install some other goodies like CoffeeScript and Forever.

npm install -g coffee-script
npm install -g forever

6. Now we can try running Node. Create an app.js file with the following Hello World code, replacing the port with the port your webapp is listening on. Then run node app.js. If you open “http://node.username.webfactional.com” in your browser you should see the Hello World text.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

Discussion

Works perfectly, almost! :) .. I’m having trouble getting nodemon to run properly. I get the error: “execvp(): No such file or directory”.

Luke,
Did you try posting your question to the WebFaction forums? The community is usually pretty helpful.

Got node working on my Webfaction server thanks to you! Thanks! Couldn’t get their tutorial working http://community.webfaction.com/questions/4888/install-nodejs-with-express-framework

Corey,
Great! Thanks for leaving a comment. It’s always nice to hear when people find these posts helpful. :)

But how will you be able to update node to newer version?

@JCK,
Good question! This example was just a simple installation from source to show how to get Node up and running on WebFaction. For updates or to manage multiple versions I would use nvm or nave.

Thanks for sharing this. Works like a charm :)

Hi, if the new version of node.js release, do u know how to update it? it’s run the same code? and if we need to create other node app, did we need to install separate nodejs for each node app?

thank.