简体   繁体   中英

express not found - `-bash: express: command not found`

I'm using this tutorial to install express so was running:

$ sudo npm install -g express

it passed successfully:

Password:
express@4.13.4 /usr/local/lib/node_modules/express
├── escape-html@1.0.3
├── content-type@1.0.1
├── cookie-signature@1.0.6
├── methods@1.1.2
├── vary@1.0.1
├── parseurl@1.3.1
├── etag@1.7.0
├── path-to-regexp@0.1.7
├── content-disposition@0.5.1
├── serve-static@1.10.2
├── range-parser@1.0.3
├── utils-merge@1.0.0
├── array-flatten@1.1.1
├── fresh@0.3.0
├── merge-descriptors@1.0.1
├── cookie@0.1.5
├── depd@1.1.0
├── qs@4.0.0
├── on-finished@2.3.0 (ee-first@1.1.1)
├── debug@2.2.0 (ms@0.7.1)
├── finalhandler@0.4.1 (unpipe@1.0.0)
├── proxy-addr@1.0.10 (forwarded@0.1.0, ipaddr.js@1.0.5)
├── type-is@1.6.12 (media-typer@0.3.0, mime-types@2.1.10)
├── send@0.13.1 (destroy@1.0.4, ms@0.7.1, statuses@1.2.1, mime@1.3.4, http-errors@1.3.1)
└── accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.10

but when I try to run as the tutorial says:

$ express donuts

I get:

-bash: express: command not found

am i missing something?

To create a express application skeleton, Express provides a command line tool ( express-generator : application generator tool) and using this you can create a application skeleton to quickly.

Install express-generator with the following command:

$ sudo npm install express-generator -g

And after a successful installation check installed version using the following command:

$ express -V

To see the available command options use the -h option:

$ express --help

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -e, --ejs           add ejs engine support (defaults to jade)
        --hbs           add handlebars engine support
    -H, --hogan         add hogan.js engine support
    -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory

And the following creates an Express app named myapp in the current working directory:

$ express myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.jade
   create : myapp/views/layout.jade
   create : myapp/views/error.jade
   create : myapp/bin
   create : myapp/bin/www

To install dependencies run the following command:

$ npm install

In your case you have installed the express framework globally not express application generator tool.

For more reference see the following link - http://expressjs.com/en/starter/generator.html

Hope this will help you !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM