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 th
Digging up an old thread here BUT I had this same error and I resolved by navigating to the directory my NodeApp resides in and running npm install -d
D:\learn\Node.js\node app.js
module.js:549
throw err;
^
Error: Cannot find module 'body-parser'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
Sometimes version not match with package.json Fixed the problem by checking the package.json then use the following commands: npm install body-parser@1.13.2 it resolved for me.
After you do express in your terminal, then do
npm install
To install all the dependencies.
Then you can do node app to run the server.
npm install from within your app directory will fix the issue as it will install everything required
You have your express module located in a different directory than your project. That is probably the problem since you are trying to require()
it locally. Try moving your express module from /Users/feelexit/nvm/node_modules/express to /Users/feelexit/WebstormProjects/learnnode/node_modules/express. This info can give you more detail about node_module file structures.
for this scenario run npm install express command using your cmd prompt for the respective folder where you want to run the program. Example I want to run the express module program server.js in F:\nodeSample. So run "npm install express" in that particular folder then run server.js