node.js, Error: Cannot find module 'express'
express, node.js
Solution
It says
Cannot find module 'express'
Do you have express installed? If not then run this.
npm install express
and run your program again.
Problem
I am new to Node.js, try to learn express to build my first web application. I got stuck on my very first sample code and need some help to get it running. Before I post this question, I did search on stack overflow, found some similar questions but still 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 to express: /Users/feelexit/nvm/node_modules/express ``` here's my sample code: this file locates 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 command `node index.js` I get following error message, please help me to fix it. Thank you. ``` 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$ ``` Update to answer chovy's 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 ```