Node.js, Error: cannot find module 'express'

I'm new to node.js, try to learn how to express your first web application. stuck on my very first code example. need help to make it work. Before I post this question, I looked at the stack overflow, found some similar questions, but could not fix it.

Error: cannot find module 'express'

I am using mac os 10.8.2. I have node.js installed using nvm.

node.js: 0.8.20 path to node: /Users/feelexit/nvm/v0.8.20/bin/node path for expression: / Users / feelexit / nvm / node_modules / express

here is my sample code: this file is located at:

/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js

var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('welcome to express'); }); app.listen(3000); 

when I try to run this node index.js file "

I am getting the following error message, please help me fix this. thank.

 Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Object.<anonymous> (/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js:1:81) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) feelexits-Mac:node_modules feelexit$ 

Refresh to answer chovy question:

 feelexits-Mac:~ feelexit$ npm install npm ERR! install Couldn't read dependencies npm ERR! Error: ENOENT, open '/Users/feelexit/package.json' npm ERR! If you need help, you may report this log at: npm ERR! <http://github.com/isaacs/npm/issues> npm ERR! or email it to: npm ERR! <npm-@googlegroups.com> npm ERR! System Darwin 12.2.0 npm ERR! command "/Users/feelexit/nvm/v0.8.20/bin/node" "/Users/feelexit/nvm/v0.8.20/bin/npm" "install" npm ERR! cwd /Users/feelexit npm ERR! node -v v0.8.20 npm ERR! npm -v 1.2.11 npm ERR! path /Users/feelexit/package.json npm ERR! code ENOENT npm ERR! errno 34 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Users/feelexit/npm-debug.log npm ERR! not ok code 0 
+72
express
Feb 19 '13 at 3:02
source share
14 answers

It says

  Cannot find module 'express' 

Do you have a feature installed? If not, run this.

  npm install express 

And run your program again.

+89
Jul 18 '13 at 11:03
source share

After you express in your terminal, do

  npm install 

To install all the dependencies.

Then you can make a node application to start the server.

+31
01 Nov '13 at 18:03
source share

Check if the express module is installed. If not, use the following command:

 npm install express 

and if your node_modules directory is in another place, set the variable NODE_PATH envirnment:

 set NODE_PATH=your\directory\to\node_modules;%NODE_PATH% 
+29
Nov 22 '13 at 10:23
source share

npm install from your application directory will fix the problem as it will install everything you need

+9
Nov 30 '13 at 20:19
source share

Digging out the old thread here, but I had the same error, and I decided by going to the directory where my NodeApp is located and npm install -d works

+5
Nov 23 '13 at 2:20
source share

You have an express module located in a different directory than your project. This is probably a problem since you are trying locally require() . Try moving your express module from / Users / feelexit / nvm / node_modules / express to / Users / feelexit / WebstormProjects / learnnode / node_modules / express . This information may provide you with more detailed information on the file structures of node_module.

+3
Feb 19 '13 at 13:06 on
source share

if the main file youre is located in /Users/feelexit/WebstormProjects/learnnode/node_modules/index.js then the expression should be located at /Users/feelexit/WebstormProjects/learnnode/node_modules/node_modules since node is always looking for modules in ./node_modules ( and its internal folder) when the path does not start with ./ or / ( more details here )

I think you skipped the main youre file in the module folder

+2
Jul 18 '13 at 11:13
source share

for this scenario, run the npm install express command using the cmd command for the appropriate folder in which you want to run the program. Example. I want to run the server.js express module program in F: \ nodeSample. So run "npm install express" in this particular folder, then run server.js

+2
Aug 26 '16 at 0:11
source share

If you do not install Node_PATH , the only option is to install express in the application directory, for example npm install express --save . Express may already be installed, but node cannot find it for any reason.

+1
Nov 07 '17 at 21:56 on
source share

npm ERR! Error: ENOENT, open '/Users/feelexit/package.json'

This is due to lack of permissions or unrelated files while npm is running.

The value executed by npm , as this user does not have sufficient permissions to read / write from the file, in this case package.json.

try adding sudo in front of the whole team - it should decide.

$ sudo npm install -g express
$ Password:*******

The password will be your administrator password for your Mac.

Flag

-g install this module (express) in the global context of node - that means node will / should recognize the express module from any js file without the need to provide the full path to the module to use.

Hope this helps!

0
Nov 08 '14 at 11:38
source share

I had the same problem. My problem was that before installing express, I have to go to the Node.js project directory on the command line.

 cd /Users/feelexit/WebstormProjects/learnnode/node_modules/ 
0
Feb 24 '15 at 2:05
source share

I assume this is a term paper from the Colt Steele Web Development course ... I was looking for the same answer, why did I end this error too. Colt doesn't talk about it, but you take node_module and go to the new folder you are working in ... something that worked for me.

0
Jul 25 '16 at 0:26
source share

Run the npm install express body-parser cookie-parser multer --save in the same nodejs source directory to solve this problem. P / s: check your directory after starting to understand more!

0
Aug 22 '16 at 15:48
source share

In rare cases, the npm cache may be damaged. For me it worked:

 npm cache clean --force 

Typically, the package manager will detect corruption and redial on its own, so this is usually not required. However, in my case, Windows 10 crashed several times, and I suspect that it might have been during the fetch operation. Hope this helps someone!

Additional information: https://docs.npmjs.com/cli/cache

0
Oct 25 '17 at 14:15
source share



All Articles