Nodejs troubleshooting

I kept getting many errors in npm install

seems that the error comes from symlink not being able to work in vagrant
partial solution: run ‘$ sudo npm install –no-bin-links’
The reason you are getting errors is because you are in vagrant synced folder. If you go to a non synced folder the error will not occur. You can also change vagrant to accept symlink on shared/synced folder. Instructions at

Tried to run “$ npm run build” for use in browserify but got this error.

/usr/bin/env: node: No such file or directory
npm ERR! weird error 127
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read

npm ERR! not ok code 0

The solution was to run
$ sudo apt-get install nodejs-legacy

If you don’t have the latest version of npm errors may occur when installing packages
# check version in server. npm current version is shown in
$ npm -v
# install latest version. you must run this twice I dont know why.
$ sudo npm install -g npm@latest


iptables is a unix firewall.  The name is not self descriptive.  Below are some notes I gathered.

Allow node.js port 3000 to be accessed outside the machine.  Vagrant (the inside) and windows (the outside).  The 1st one is to add a rule to the beginning and the 2nd is to append at the end of all the rules.  Ultimately they are the same.  Be careful with the second one because rules before will take preference.
$ sudo iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT

Using Iptables on Linux

Getting started with Node.js and express

# working in ubuntu 12.04

# add package to get latest version to not get errors
sudo add-apt-repository –yes ppa:chris-lea/node.js
sudo apt-get update

# install node.js and npm
sudo apt-get install nodejs npm

# install express framework
$ sudo npm install -g express
$ sudo npm install -g express-generator

# create project
$ express testexpress
$ cd testexpress
$ sudo npm install

# or if you wish to create project with hogan (handlebars) and less
$ express testexpress –hogan -c less

# to run the app
$ DEBUG=testexpress ./bin/www

# miscellaneous
$ npm install -g nodemon

// add code to bottom of app.js to run as 
// $ node app.js
module.exports = app;
/* Use PORT environment variable if it exists */ 
var port = process.env.PORT ||3000;
server = app.listen(port);
console.log('Server listening on port %d in %s mode', server.address().port, app.settings.env);