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/');
Both comments and pings are currently closed.

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.

Papa Kwame Anane

Wow!!.. worked without a hitch thanks Rob.. any “simple” tips on couchdb? following you on twitter..

@Papa,

Glad to hear it! Sorry, I haven’t worked with CouchDB. But if you Google it I’m sure you’ll find some instructions in the WebFaction forums or elsewhere.

Aron Griffis

Why the -g on npm install? The npm man-page isn’t a huge help, but I would expect a global install to be system-wide and these are installs to the local homedir.

@Aron,
Good question. The global install is relative to the Node installation, which is installed with the home directory. i.e., global node modules are placed in `{prefix}/lib/node_modules`, where {prefix} is $HOME. So -g isn’t server-wide but environment-wide, in the sense of WebFaction’s shared server environments.

Works like a charm, except for the npm installation.
Seems like npmjs.org enforces the use of the secured version of the site. I got it to work with (in case anyone else has the same issue)

curl -k https://npmjs.org/install.sh | bash

remoteless

Thanks for the great info. I would have never found the installation package without this.

I could not get ./configure to work with –jobs. It is not listed as a parameter in ./configure –help.

I used this:
./configure –prefix=$HOME

remoteless

Thanks to Daniel R. for the https npm install link. worked like a charm.

curl -k https://npmjs.org/install.sh | bash

Daniel Martins

I need to put on first line python2.7.

because on the webfaction the default python is 2.4.3 and throw up an syntax error with latest nodejs package.

Anyway, thanks for sharing the procedure!

Yohei Yamaguchi

Hello,

In step 3, the command line “./configure –jobs=1 –prefix=$HOME
make install”. Is this supposed to type in the “src” directory, which is generated in step1?

I get an error “-bash: configure: command not found”

My node version is “node-v0.10.15″

Thanks for your help!