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
1 Answer
Reset to default 3Node 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.