Reputation: 67
Why express command not found. Here is the path for express.
/usr/lib/node_modules/express
When I install the express, the terminal shows the path. I used
npm install -g express-generator
npm install -g express
But when I run express, it doesn't work. In this directory, express is globally right? But why can't be found. I don't understand the logic.
Upvotes: 2
Views: 1323
Reputation: 1694
You need to install express locally, rather than globally.
http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation
In general, the rule of thumb is:
- If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
- If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
Based on this, you want to install express-generator
using the -g
flag as you will use it as a command line tool, but you want to install express
without this flag as it's a module you will want to require()
it in your application.
Take a look at the installation guide:
http://expressjs.com/starter/generator.html
It says to install the express-generator
module as a global module as you will use it as a command line utility to scaffold your new applications.
Once you have scaffolded an application using the express myapp
command, you just have to run npm install
in the myapp
directory which will download the rest of the dependencies to your projects local ./node_modules
directory. It does this by reading the contents of the generated package.json
file.
Lesson to take away: Don't install with the -g
flag unless the modules instruction guide explicitly says to do so.
Upvotes: 2