最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - module.js:327 Error: Cannot find module 'express' - Stack Overflow

programmeradmin0浏览0评论

Hello I am new in a nodejs and when I run any file in mand prompt like:-

C:\demoData>node demo.js

I get error li9ke this

module.js:327
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\demoData\shahzad.js:1:77)
    at Module._pile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

I did R&D and get the solution

npm install express

And my Problem has solved using this. But Why I required this I have already express folder globally.this path

C:\Users\broswire\AppData\Roaming\npm\node_modules;

I want to use this node_modules, I don't want locally node_modules.

Hello I am new in a nodejs and when I run any file in mand prompt like:-

C:\demoData>node demo.js

I get error li9ke this

module.js:327
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\demoData\shahzad.js:1:77)
    at Module._pile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

I did R&D and get the solution

npm install express

And my Problem has solved using this. But Why I required this I have already express folder globally.this path

C:\Users\broswire\AppData\Roaming\npm\node_modules;

I want to use this node_modules, I don't want locally node_modules.

Share Improve this question asked Jul 14, 2016 at 10:16 shahzad ahmedshahzad ahmed 1812 gold badges5 silver badges13 bronze badges 3
  • Is express installed globally? Does C:\Users\broswire\AppData\Roaming\npm\node_modules\express exist? – Vladimir G. Commented Jul 14, 2016 at 10:18
  • @user1280859: yes this folder exist – shahzad ahmed Commented Jul 14, 2016 at 10:19
  • Check answer from this issue github./nodejs/node/issues/3865 . And it's realy bad practice to install libs like express globally – Vladimir G. Commented Jul 14, 2016 at 10:22
Add a ment  | 

1 Answer 1

Reset to default 3

Node encourages using locally installed modules. Generally, using modules installed with npm install --global or npm install -g should be reserved for cli tools and things used systemwide. So to use express in a project, it is remended to npm install express in that directory. It is also useful to add a package.json file to save the versions of your dependencies. Then you can just navigate to your project and run npm install and it will install the required dependencies.

发布评论

评论列表(0)

  1. 暂无评论