Ubuntu: npm installed packages are not accessible



Question:

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

express@3.4.4 node_modules/express  â"œâ"€â"€ methods@0.1.0  â"œâ"€â"€ range-parser@0.0.4  â"œâ"€â"€ cookie-signature@1.0.1  â"œâ"€â"€ fresh@0.2.0  â"œâ"€â"€ debug@0.7.4  â"œâ"€â"€ buffer-crc32@0.2.1  â"œâ"€â"€ cookie@0.1.0  â"œâ"€â"€ mkdirp@0.3.5  â"œâ"€â"€ commander@1.3.2 (keypress@0.1.0)  â"œâ"€â"€ send@0.1.4 (mime@1.2.11)  â""â"€â"€ connect@2.11.0 (methods@0.0.1, uid2@0.0.3, pause@0.0.1, raw-body@0.0.3, qs@0.6.5, bytes@0.2.1, negotiator@0.3.0, multiparty@2.2.0)  

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


Solution:1

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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »