Express js installation error in node - node.js

While trying to install express js by the command "npm install -g express" in cmd prompt in windows it shows the following error
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> (D:\chapter3\sample-app\web-server.js:1:77)
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)
at Function.Module.runMain (module.js:497:10)
How to fix this and run a web server?

You shouldn't install express globally. cd into your project directory, then npm install express.
Global package install is meant to install command line utilities; project dependencies should be installed locally, see npm's FAQ and this blog post.

Related

Gulp watch not working - cannot find module connect

Trying to run my project using gulp (havent used gulp before and have inherited an exisiting project).
I install the dependencies into the wordpress theme directory.
Running gulp watch throws this error:
Error: Cannot find module 'connect'
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:\dev\projects\romac-website\web\app\themes\romac\node_modules\browser-sync\lib\utils.js:307:31)
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)
I have tried to update npm but not sure if it is fine or the problem (still).
I also tried to ins install this module with npm -g install connect
What should I try next?
Try deleting the node-modules folder then reinstall npm install connect --save-dev Then retry running gulp

Node error trying to run yeoman

I am trying to use yeoman to scaffold for a webapp. when I try and do anything with node I get error thrown. Below is my command line output when I try and 'update node' and when i try and run 'yo webapp'. Can anyone help point out the error?
$ node update
module.js:340
throw err;
^
Error: Cannot find module '/Users/william/wdi/pixelect_project/pixelect_client_server/update'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
$ yo webapp
module.js:340
throw err;
^
Error: Cannot find module 'inquirer'
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> (/usr/local/lib/node_modules/yo/node_modules/insight/lib/index.js:9:16)
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)
at Module.require (module.js:364:17)
I had same problem. I my case helped this: npm install -g yo
For me this is also happening with other node apps as well (eg. grunt and gulp).
Reinstalling it does the trick. In this case you have to reinstall generator-webapp (npm install -g generator-webapp). If after reinstalling generator you get the same message than reinstall yeoman as levon suggested.

Meteor bundle error on startup

I have an issue with meteor bundle. I try to start bundle with foreverjs but get error
root#ip-172-31-0-83:/home/ubuntu/bundle# cat ../logs/forever.log
module.js:340
throw err;
^
Error: Cannot find module 'fibers'
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> (/home/ubuntu/bundle/programs/server/boot.js:1:75)
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)
at Module.require (module.js:364:17)
error: Forever detected script exited with code: 8
I tried install fibers via npm
npm install fibers -g
,also I've tried install in local meteor node_modules dir.
But unfortunately error stays.
Version of meteor is 0.9.1.1
The procedure to install Fibers has changed in 0.9.x+
From the docs:
cd bundle
cd programs/server
npm install
Also, the correct setup instructions (for a bundle built by any version of Meteor) can be found in the bundle's README file.

Node js Express module.js:340

I'm having trouble running my app in node. When I first got the module.js:340 error, I used a sudo npm install express -g, and it looked like Express is installed but when I run my app again I get this error.
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> (/Users/mac/Downloads/node-FED-master/app.js:6:15)
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)
at Function.Module.runMain (module.js:497:10)
users-Mac-Pro:node-FED-master mac$
You've installed Express globally (with -g), which gives you access to the express command line tool, but Node programs can't access the global module. You need to install Express locally by doing npm install express in your project directory.
If the project has a package.json, a simple npm install in the project directory will install all necessary dependencies in it's correct versions.

error running app after new install on Amazon EC2

For the first time trying to use Amazon EC2 to install node.js server. Doing according to this article. Installed node.js, then npm, then all the other modules. All without error. But for some reason, my server does not start. Can you please tell me where to find the error?
[ec2-user#domU-12-31-39-07-62-87 ~]$ node server.js
module.js:340
throw err;
^
Error: Cannot find module 'socket.io'
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> (/home/ec2-user/server.js:3:10)
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)
[ec2-user#domU-12-31-39-07-62-87 ~]$ cd node
[ec2-user#domU-12-31-39-07-62-87 node]$ node server.js
module.js:340
throw err;
^
Error: Cannot find module '/home/ec2-user/node/server.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
It looks like it just couldn't find socket.io. Try this:
cd /home/ec2-user
npm install socket.io
node server.js
I agree with "The Reddest", however, the article says to install express which should install socket.io as a dependency. Did you run the last two npm commands in the article?
sudo npm install express -g
sudo npm install forever -g
Better yet, create a package.json file and install its dependencies local to the app rather than globally. Read more about that, here .. http://docs.nodejitsu.com/articles/getting-started/npm/what-is-the-file-package-json

Resources