login community faq
2
3

How do I install Node.js with the express framework?

asked Aug 16 '11 at 02:51

ryans's gravatar image

ryans ♦♦
28161420

edited Apr 29 at 18:55

seanf's gravatar image

seanf ♦♦
55991220


This can be done in two steps:

  1. Create a new application of type Custom Application (Listening on port)
  2. Install node.js, npm (the node package manager), and the express framework into your account

Step 2 can be performed using the following commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mkdir -p $HOME/src
cd $HOME/src
wget 'http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz'
tar -xzf node-v0.10.5.tar.gz
cd node-v0.10.5

# All of these scripts use "#!/usr/bin/env python". Let's make that mean python2.7:
PATH_BACKUP="$PATH"
mkdir MYPY
ln -s $(which python2.7) $PWD/MYPY/python
export PATH="$PWD/MYPY:$PATH"

./configure --prefix=$HOME
make         # 5.5m
make install

# restore the PATH (we don't need `$PWD/MYPY/python` anymore).
# Then, make sure $HOME/bin is on the PATH
PATH="$PATH_BACKUP"
export PATH=$HOME/bin:$PATH
echo 'export PATH="$HOME/bin:$PATH"' >> $HOME/.bashrc
hash -r

# Set the node modules path
export NODE_PATH="$HOME/lib/node_modules:$NODE_PATH"
echo 'export NODE_PATH="$HOME/lib/node_modules:$NODE_PATH"' >> $HOME/.bashrc

# now install express framework
cd $HOME
npm install -g express
npm install -g stylus
npm install -g jade

# create express framework "hello world" project
mkdir -p $HOME/node_projects
cd $HOME/node_projects
express -s -c stylus helloworld
cd helloworld

# use the PORT from your Custom Application created at the beginning!
PORT=8888
sed -i "s/app.set('port', process.env.PORT || 3000);/app.set('port', process.env.PORT || $PORT);/" app.js

# run it
cd $HOME/node_projects/helloworld
node app.js

Hope that helps!

This answer is marked "community wiki".

answered Aug 16 '11 at 02:56

ryans's gravatar image

ryans ♦♦
28161420

edited Apr 29 at 18:54

seanf's gravatar image

seanf ♦♦
55991220

Thanks for this guide, but how do you then view the application? How do you point a domain at the helloworld application?

(Sep 01 '11 at 06:57) AnnaPS AnnaPS's gravatar image

Hi,

You need to assign this app to a website. Requests made for this website will then be forwarded to the port assigned to the app.

I hope this clears it up.

(Sep 01 '11 at 07:00) todork todork's gravatar image

Yep, the problem is that the app is located at $HOME/helloworld: with Webfaction, doesn't it need to be at $HOME/webapps/helloworld in order to be spotted as an app?

(Sep 01 '11 at 07:18) AnnaPS AnnaPS's gravatar image

No, that's not the case here. When you assign a "Custom Application (Listening on port)" app to a site, it's just used as a placeholder so nginx (the frontend web server) can forward the requests for this site to the correct port. To map the app to this site, you just need to make sure that it's configured to run on the correct port.

(Sep 01 '11 at 10:27) todork todork's gravatar image

require.paths.push has been deprecated. Add this to your ~/.bash_profile instead:

export NODE_PATH=$HOME/lib/node_modules:$NODE_PATH

(Apr 03 '12 at 20:57) keenans keenans's gravatar image

It's been almost a year since this was first posted - are there any plans to add a node installer?

btw - these instructions are not working for me with node version 0.8.4.

(Aug 02 '12 at 09:01) Tex Tex's gravatar image

No, we still have no plans to add a Node installer - there's an updated guide written by one of our users here: Real-World node.js (using Webfaction) - Part 1

(Aug 02 '12 at 13:37) seanf ♦♦ seanf's gravatar image

The source for npm has been updated to https://npmjs.org/install.sh

Great guide!

(Sep 03 '12 at 05:22) Aventus Aventus's gravatar image

Thanks, I've edited the original answer to reflect the new install URL.

(Sep 03 '12 at 05:33) todork todork's gravatar image

Also worth noting that as of the 0.6 branch, npm is bundled with node so no need to install it separately

(Sep 04 '12 at 15:44) Dave Stevens Dave%20Stevens's gravatar image

I've now updated this guide from node 0.4.12 to 0.8.9, and the above issues should be fixed. Hope that helps!

(Sep 23 '12 at 22:03) ryans ♦♦ ryans's gravatar image

I'm Happy! Thanks :)

(Oct 17 '12 at 19:24) marcoslhc marcoslhc's gravatar image

Thanks for this guide. It worked perfectly. Initially, I tried other methods to get around the python problem, but this did the trick. Thanks again!

(Nov 01 '12 at 21:04) wchest wchest's gravatar image

Hai, Am getting this error while giving the command npm install -g express

root@otc-desktop:~# npm install -g express npm http GET https://registry.npmjs.org/express npm http GET https://registry.npmjs.org/express npm http GET https://registry.npmjs.org/express npm ERR! Error: tunneling socket could not be established, cause=socket hang up npm ERR! at ClientRequest.onError (/root/lib/node_modules/npm/node_modules/request/tunnel.js:161:17) npm ERR! at ClientRequest.g (events.js:185:14) npm ERR! at ClientRequest.EventEmitter.emit (events.js:88:17) npm ERR! at CleartextStream.socketErrorListener (http.js:1330:9) npm ERR! at CleartextStream.EventEmitter.emit (events.js:88:17) npm ERR! at SecurePair.exports.connect.cleartext._controlReleased (tls.js:1267:15) npm ERR! at SecurePair.EventEmitter.emit (events.js:88:17) npm ERR! at SecurePair.error (tls.js:921:10) npm ERR! at EncryptedStream.CryptoStream._done (tls.js:395:17) npm ERR! at EncryptedStream.CryptoStream._pull (tls.js:546:12) npm ERR! If you need help, you may report this log at: npm ERR! http://github.com/isaacs/npm/issues npm ERR! or email it to: npm ERR! npm-@googlegroups.com

npm ERR! System Linux 2.6.32-41-generic npm ERR! command "/root/bin/node" "/root/bin/npm" "install" "express" npm ERR! cwd /root npm ERR! node -v v0.8.9 npm ERR! npm -v 1.1.61 npm ERR! code ECONNRESET npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /root/npm-debug.log npm ERR! not ok code 0

Pls tell me anybody how to solve this issue...

thanks, vidhya

(Dec 04 '12 at 04:41) sree sree's gravatar image

This looks like a local issue, rather than in a WebFaction environment. Since we are not aware of your local setup, our support is limited.

Judging from the error shown this looks like a network issue but I'd suggest you take a look at your /root/npm-debug.log file for more info and maybe try to the contact node's community on this issue instead.

(Dec 04 '12 at 05:56) iliasr ♦♦ iliasr's gravatar image

i just cant handle this. i tried everything. Node works good, npm works good. I can install express but when i use the command "express" always appears "command not found". I am desperate everything works except this "express module". I am using Mountain Lion OSX. I hope somebody can help

(Jan 12 at 11:18) meitoli meitoli's gravatar image
showing 5 of 16 show all

Worked perfectly with node 0.8.18 -- thanks!

answered Jan 28 at 17:04

dowdrake's gravatar image

dowdrake
1

Thanks. This was great information. Worked very well for me.

One simplification.

Instead of the convoluted tricks with MYPY, you can simply do the following:

1
2
3
4
cd node-v0.8.18/
python2.7 configure --prefix=$HOME
make PYTHON=python2.7
make PYTHON=python2.7 install

This worked perfectly for me, without having to muck around with the PATH.

answered Jan 30 at 05:04

Navin%20Kabra's gravatar image

Navin Kabra
11

edited Jan 30 at 05:21

Remember to place logs in /home/username/logs/user/ so they can be rotated. Also, to launch node at reboot, use @reboot in crontab.

I use forever to keep node running, and launch it on reboot (via forever) through crontab.

answered Apr 01 at 09:00

Madsn's gravatar image

Madsn
32

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×21
×4

Asked: Aug 16 '11 at 02:51

Seen: 12,443 times

Last updated: Apr 29 at 18:55

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited