5
votes

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"
  }
}
1
Use require('./FtseData') instead of require('./routes/FtseData') if FTseData is in routes folder, and routes.js is also in same routes folderSantosh
routes.js is in the root folder with server.js. FtseData.js is located in /routes folder. If i had the path wrong it wouldnt work on my local machine, but it doesuser2202098
i had to put the file extension on require statement. require('./routes/FtseData'); to be require('./routes/FtseData.js');user2202098

1 Answers

5
votes

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');