npm installed packages are not accessible

I installed nodejs with the instructions from this post on ubuntu 13.1 All went smooth. After that I installed express by issuing the command

npm install express

which result in

[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

but when I now type something like

express demo

I get

The program 'express' is currently not installed. You can install it by typing: sudo apt-get install node-express


I answer my own question for the case that someone else stumble over the same problem.

The packages can be installed as local and global where local is default. We should install the package as local when we require it and as global when we want to access it within the shell. To install a package as global simply add -g in my case I run

sudo npm install -g express

and now it works.

Edit

Using -g and require it later can lead to UNMET DEPENDENCY express this can be solved by using -d

sudo npm install -d express