Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js AWS deployment Error: Cannot find module

I am attempting to upload a simple Node?JS app onto elastic beanstalk. All dependencies are listed in my package.json file and the app is listening on 8081 through nginx proxy.

The following error is being thrown from the node log file. Are the modules placed differently on the server ?

Server running at http://127.0.0.1:8081/ module.js:471 throw err; './routes/FtseData' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/var/app/current/routes.js:7:20) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) module.js:471 throw err; ^

Error: Cannot find module './routes/FtseData' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/var/app/current/routes.js:7:20) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) module.js:471 throw err; ^

Here is my server.js file

var express = require('express');
var basicAuth = require('express-basic-auth')
var bodyParser = require('body-parser')
var cors = require('cors');
var app = express();

app.use(cors()); 

app.get('/', function (req, res) {
//    res.send('Hello World');
    res.sendFile(__dirname + '/views/index.html');
})

var routes = require('./routes');
app.use('/api', routes);


var server = app.listen(8081, function () {
   var host = server.address().address
   var port = server.address().port

   console.log("App listening at http://%s:%s", host, port)
})

routes.js

var express = require('express');
var basicAuth = require('express-basic-auth')
var app = express();
var router = express.Router();

//var profCtrl = require('./routes/profileController');
var ftseDataCtrl = require('./routes/FtseData');
var ftseDivCtrl = require('./routes/FtseDiv');

//routes not needing auth
router.route('/FtseDivGet').get(ftseDivCtrl.get);
//routes needing auth
 router.use(basicAuth({
     users: { 'admin': 'supersecret' }
 }))
//router.route('/FtseDataScrape').get(ftseDataCtrl.scrape);
router.route('/FtseDivScrape').get(ftseDivCtrl.scrape);
//http://localhost:8081/api/profile

module.exports = router;

package.json

{
  "name": "StockTracker",
  "version": "1.0.0",
  "description": "Stock-Tracker",
  "dependencies": {
    "express": "*",
    "express-basic-auth": "*",
    "request": "*",
    "cheerio": "*",
    "body-parser": "*",
    "cheerio-tableparser": "*",
    "cors": "*",
    "csv-load-sync": "*"        
  },
  "scripts": {
    "start": "node server.js"
  }
}
like image 593
user2202098 Avatar asked Jun 04 '17 13:06

user2202098


1 Answers

My file was /routes/FtseData.js

This caused the error

var ftseDataCtrl = require('./routes/FTSEData');

Case needed to match file

var ftseDataCtrl = require('./routes/FtseData');
like image 89
user2202098 Avatar answered Sep 21 '22 01:09

user2202098