5

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"
  }
}
3
  • Use require('./FtseData') instead of require('./routes/FtseData') if FTseData is in routes folder, and routes.js is also in same routes folder Commented Jun 4, 2017 at 14:04
  • 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 does Commented Jun 4, 2017 at 14:22
  • i had to put the file extension on require statement. require('./routes/FtseData'); to be require('./routes/FtseData.js'); Commented Jun 4, 2017 at 17:42

1 Answer 1

5

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');
Sign up to request clarification or add additional context in comments.

3 Comments

But the nodejs doc suggest that it will automatically try to add .js , .json and finally .node here
I have tested it again. Your are correct. The issue appears to be casing in the filename. Thanks
Thanks for coming back to answer your own question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.