Node.js Error: Cannot find module express

Dmitry

I wrote my first node.js app, but it can't find express library:

C:\ChatServer\Server>node server.js

module.js:340
    throw err;
          ^
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:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:6:9)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:25:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

But express is intalled (with -g key):

C:\ChatServer\Server>npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.7.11
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.4
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/send/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/mkdirp/0.3.4
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/connect/2.7.11
npm http 304 https://registry.npmjs.org/commander/0.6.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/send/0.1.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No readme data.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/send/0.1.1
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/bytes/0.2.0
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/formidable/1.0.14
npm http 304 https://registry.npmjs.org/qs/0.6.5
npm http 304 https://registry.npmjs.org/send/0.1.1
npm http 304 https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
C:\Users\Dmitry\AppData\Roaming\npm\express -> C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express\bin\express
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
[email protected] C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Some information:

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>node --version
v0.10.9

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>npm ls -g installed express
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
C:\Users\Dmitry\AppData\Roaming\npm
└── [email protected]


C:\ChatServer\Server>npm ls installed express
C:\ChatServer\Server
└── (empty)

How can I solve this problem? (MUST I install it without -g?)

Golo Roden

You need to install Express locally into the context of your application (node_modules folder):

$ npm install express

The reason for this is that applications always look in their local context for any dependencies. The global installation is only for setting up system-wide available binaries, such as unit test runners or bootstrappers or things like that.

With Express, when you install it globally, you get an express binary that can bootstrap an application for you. For more information, type

$ express --help

So, to answer your final question: YES, you need to install it without -g.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

ERROR in Cannot find module 'node-sass'

From Java

How do I resolve "Cannot find module" error using Node.js?

From Dev

Heroku + Node: Cannot find module error

From Dev

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

From Dev

Node js and phantomjs - Cannot find module 'weak'

From Dev

Handling "Cannot find module" error when calling node.js fork

From Dev

"Error: Cannot find module 'pkginfo'" - node js app deploying to heroku

From Dev

Node.js Express JS - Could not find module

From Dev

Node.js Error: Cannot find module 'request'

From Dev

php-node Node Express cannot find module

From Dev

Node.js cannot find an installed module

From Dev

Error: Error: Cannot find module ' in angular js?

From Dev

How to fix Node.js error: Cannot find module 'immer'

From Dev

Node.js: Cannot find module 'chai'

From Dev

Node.js - Error: Cannot find module 'config/chgpass'

From Dev

Node.js electron-prebuilt error cannot find module 'browser-window' windows 10

From Dev

module.js:327 Error: Cannot find module 'express'

From Dev

How to resolve “Cannot find module” (custom module) error in express.js

From Dev

Node js and phantomjs - Cannot find module 'weak'

From Dev

Node.js "Error: Can not find module"

From Dev

cannot find node.js module

From Dev

express error - cannot find module - static file

From Dev

Error: Cannot find module 'node-wit'

From Dev

Error: Cannot find module 'html' with Node.JS and Express

From Dev

Node.js error: Cannot find module 'firebase/storage'

From Dev

Error: Cannot find module 'node-jsdom

From Dev

Cannot find module express

From Dev

Cannot find module './*.env' node js

From Dev

Node.js Express Error: Cannot find module

Related Related

HotTag

Archive