express is not recognized in cmd in windows 7

2019-09-02 05:07发布

问题:

js on my windows 7 machine, i have executed the below commands from

C:\node> npm install -g express -generator

and also C:\node> npm install -g express -generator@4, and also the npm link express

for the above commands, i got the below messages.

express@4.10.7 C:\Users\user1\AppData\Roaming\npm\node_modules\express
├── methods@1.1.1
├── finalhandler@0.3.3
├── cookie-signature@1.0.5
├── serve-static@1.7.2
├── merge-descriptors@0.0.2
├── utils-merge@1.0.0
├── range-parser@1.0.2
├── media-typer@0.3.0
├── cookie@0.1.2
├── content-disposition@0.5.0
├── parseurl@1.3.0
├── vary@1.0.0
├── escape-html@1.0.1
├── fresh@0.2.4
├── path-to-regexp@0.1.3
├── depd@1.0.0
├── qs@2.3.3
├── on-finished@2.2.0 (ee-first@1.1.0)
├── etag@1.5.1 (crc@3.2.1)
├── debug@2.1.1 (ms@0.6.2)
├── type-is@1.5.5 (mime-types@2.0.7)
├── accepts@1.1.4 (negotiator@0.4.9, mime-types@2.0.7)
├── send@0.10.1 (destroy@1.0.3, ms@0.6.2, mime@1.2.11, on-finished@2.1.1)
└── proxy-addr@1.0.4 (forwarded@0.1.0, ipaddr.js@0.1.5)

and with npm link express:

C:\node\node_modules\express -> C:\Users\user1\AppData\Roaming\npm\node_modul es\express

but still when i execute the express nodetest1 at C:/node> i am getting the express is not recognized error.

anyone know any pointers would be helpful.

回答1:

You have a space between express and -generator above... if this was copy-pasted, maybe you missed it... it's supposed to be express-generator as a single unit.


Make certain that %USERPROFILE%\AppData\Roaming\npm both exists and is in your PATH environment variable... If it isn't there, you will have to open a new prompt after adding it. Some versions of node's installer don't always create or add it correctly.


If you are using [nvm for windows] you will need to ensure that C:\Program Files\nodejs is in your path (the installer should work correctly), you'll need to run nvm via command prompt Run as Administrator. This is because nvm uses symbolic links from the global install path to a specific version under your profile to run against.

I've been using nvm for windows for a few months now (switching from 0.10.x and 0.11.x versions) and it's been a bit easier to work with.



回答2:

Make sure you are runing the command promt as System Administrator "This is very important", then do npm install -g express after that chang to the directory where you want to create your app and you are good to go. NB if you are using express 4 then install it via npm install -g express-generator@4