0

I am trying to reproduce a node.js server on an AWS EC2 instance. I have already successfully created a basic hello world page, and now have a login/authentication page that I would like to display. The webpage uses a MongoDB Database hosted on the localhost (port 80), and when I run the web page on my laptop it works fine. The JavaScript file is called server.js. From the terminal I perform the following (using Mac OS X):

$ cd /path/etc/relevantdirectory/
$ nohup sudo mongod & 
$ nohup sudo node server.js

Then using Chrome I can access the homepage fine from localhost.

However, when I try to perform the identical process from inside a AWS EC2 instance (running on Amazon Linux) I get the following error:

[ec2-user@ip-XXXXXXXXX ABC]$ sudo node server.js 

module.js:340
    throw err;
          ^
Error: Cannot find module './lib/'
    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/ec2-user/XXXXXXXX/node_modules/mongoose/index.js:7:18)
    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)
[ec2-user@ip-XXXXXXXXX ABC]$ 

I have the following Node.js packages installed:

    bcrypt-nodejs  express          morgan                  passport-local
    body-parser    express-session  node-core-module-names  passport-twitter
    connect-flash  forever          nodemon                 path
    cookie-parser  inherits         passport                serve-favicon
    debug          method-override  passport-facebook
    ejs            mongoose         passport-google-oauth

I have followed solutions from the following links:

Error: Cannot find module '../lib/cli'

Node.js Error: Cannot find module express

Node js Error: Cannot find module './lib/socket.io'

but nothing seems to be resolving the issue.

I am fairly new to Node.js and this is my first webpage that I am trying to make/host, so any advice would be gratefully received.

Community
  • 1
  • 1
oliversm
  • 1,771
  • 4
  • 22
  • 44
  • Most intrigued by why you would think you need to or even want to run your app as root ( suggest some reading on that topic ), but really have you even tried running `npm list` on the "installed" instance? My money is on nothing is actually installed. – Blakes Seven Aug 14 '15 at 10:24
  • Thanks @Blakes Seven , I found uninstalling and re-installing my `node modules` fixed the issue, and I have since removed the `sudo` (I had been using a port that required elevated privileges and had been using `sudo` to bypass the issues this raised). – oliversm Aug 26 '15 at 08:27

0 Answers0