error running app after new install on Amazon EC2 - node.js

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

Related

Getting koa to work (nodejs web framework)

I am running Deepin and trying to get koa to work. There is little documentation on the subject.
I did the following as stated on koajs.com:
$ npm install -g n
$ n 0.11
$ node --harmony my-koa-app.js
I recieve the error:
➜test-koa-app$ sudo node --harmony test-koa-app.js
module.js:338
throw err;
^
Error: Cannot find module 'koa'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/karl/nodejs/test-koa-app/test-koa-app.js:1:73)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
As Mike Kamermans mentioned in the question comments, to use a module in a node application, it must first be installed in the project directory.
To install it, run npm install koa in a terminal in your project folder.
If you've run npm init and setup a package.json file in your project, you can add the --save flag and save a record of the dependency with npm install --save koa.
Version 2 of koa now out. Go here:
https://github.com/koajs/koa

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 returns "Cannot find module 'lockit-mongodb-adapter'"

I am going through my first node.js project. I've installed lockit , have a app.js file, and when I try to run it I get this error
module.js:340
throw err;
^ Error: Cannot find module 'lockit-mongodb-adapter'
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 new module.exports (C:\Users\xx\Documents\mailer\index.js:38:44)
at Object.<anonymous> (C:\Users\xx\Documents\mailer\examples\mongodb\app. js:32:14)
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 am quite certain I have lockit-mongodb-adapter installed.
You need to install the module. Cd to the root of your app directory and run this command and make sure lockit-mongodb-adapter is in your node modules directory.
npm install lockit-mongodb-adapter
Another thing you can do if you are certain it is installed is double check to see what is installed by running this command:
npm list
And this one to see what is installed globally:
npm list -g
Update:
I was able to reproduce the issue you where having. And to resolve it I deleted the module from the node moules directory. And re-installed with the following command:
npm install lockit-mongodb-adapter -save
It now shows up in npm list with no issues:

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.

Express js installation error in node

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.

Resources