简体   繁体   中英

Getting error, Error: Cannot find module ‘express’ after npm install

I am new to both Node JS and express, and I have just installed npm in Windows 7.

I have installed express using the global flag:

npm install -g express

This sucessfully installs express in C:\\Users\\USER_NAME\\AppData\\Roaming\\npm\\node_modules\\express , and adds C:\\Users\\USER_NAME\\AppData\\Roaming\\npm to my path.

However, using express in the command line is not successful. Any command starting with express tells me it cannot find the command to execute:

 'express' is not recognized as an internal or external command,
  operable program or batch file.

Looking in the installation folder, I can't find an executable file either (an .exe or a .cmd). Googling past questions shows that the node_modules folder (at least in past versions) should contain both an express folder (which I have) and a .bin folder, which contains express.cmd . I don't appear to have the .bin folder.

npm --version gives me 1.4.3 . Express version looks to be 3.0.0

I've also tried installing it locally, and I've tried running npm cache clean and reinstalling. Neither method changes the situation: there's nothing executable in the node_modules folder.

Am I installing express incorrectly? If so, why does it not include an executable file?

I ran into the same problem on Windows 8.1. The express.cmd is not created, but I found the text file:

C:\Users\you\AppData\Roaming\npm\node_modules\express\Readme.md

It suggests to run this:

npm install -g express-generator@3

Which will download more stuff.

After that you can use on the windows command prompt. It will be in your path ( C:\\Users\\you\\AppData\\Roaming\\npm)

Edit:

express-generator@3 is now updated to express-generator@4 , so use this instead,

npm install -g express-generator@4

The answer isn't complete, because the modules are installed in C:\\Users\\you\\AppData\\Roaming\\npm directory as stated above, and you cannot always access any module without, 1) linking it to your current project or 2) explicityly defining the NODE_PATH system variable pointing your node to the right place in the system.

First method,

After installing the module ( express in our case), you can link it to your current project by going to your current project directory using cmd and executing below command,

npm link express

You will get a message like this if it is successfully linked,

D:\\Project\\node_modules\\express -> C:\\Users\\Sufiyan\\AppData\\Roaming\\npm\\node_modules\\express

(you cannot link directories without running cmd with Administrator privileges)

The second option is to create or update NODE_PATH system variable pointing your node to the right place in the system. Read this for details.

Also read this official Node.js documentation regarding the issue,

http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/

This is all you need to do:

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

You can find this and much more at this detailed start up tutorial .

To fix this you need to use:

npm install -g express-generator@3

It has been updated from the previous command:

npm install -g express

请注意,express --version命令返回的版本将是express-generator的版本,而不是express。

I had this problem, Seems though we use -g it's ignored.

I just copied contents of MyProject/source/vendor to C:\\Users\\username\\AppData\\Roaming\\npm

Copy only needed folders inside node_modules (like: express, express-generator, bower, yo, gulp and packages that should be in PATH).


This problem really bothers everyone (or windows users?), npm programmers should solve it!

Run cmd as administrator. It solved the 'express' not found problem in my case

npm link express可以将节点从任何目录链接到项目目录,默认情况下,当您运行npm install express ,它将安装在C:\\Users\\****\\AppData\\Roaming\\npm\\node_modules\\express ,因此,您不必每次都在项目目录中安装Express和其他安装所需的框架,而是可以指向您的节点,即您拥有应用程序的位置。

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