. Advertisement .
..3..
. Advertisement .
..4..
I get the error message:
Error: Cannot find module 'express'
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$
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! <[email protected]>
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
Has anyone ever faced this problem? How to troubleshoot the “ error: cannot find module ‘express’”
But the problem is appearing when I try to operate the following program
node.js: 0.8.20 path to node: /Users/feelexit/nvm/v0.8.20/bin/node
path to express: /Users/feelexit/nvm/node_modules/express
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('welcome to express');
});
app.listen(3000);
The cause: This error occurs because of missing permissions or unlinked files while npm was working. It means that executing npm as this user doesn’t have enough rights to read or write from a file, in this case is package.json.
Solution: Adding
sudo
before the entire command:Password would be your admin password of your mac.
-g
flag will set up this module (express) in the global context of node, it means that node will recognizeexpress
module from within any js file without providiing a full path to the module in use.It is a statement of fact
Are you running express? If you don’t, then follow this.
Run your program again.