Node.js AWS部署错误:找不到模块

时间:2017-06-04 13:56:24

标签: javascript node.js amazon-web-services nginx elastic-beanstalk

我正在尝试将一个简单的Node?JS应用程序上传到弹性beanstalk上。所有依赖项都列在我的package.json文件中,应用程序通过nginx代理监听8081。

从节点日志文件中抛出以下错误。模块在服务器上的放置方式是否不同?

  

服务器在http://127.0.0.1:8081/ module.js运行:471       扔错了;        ' ./路由/ FtseData'       在Function.Module._resolveFilename(module.js:469:15)       在Function.Module._load(module.js:417:25)       在Module.require(module.js:497:17)       at require(internal / module.js:20:19)       在对象。 (/var/app/current/routes.js:7:20)       在Module._compile(module.js:570:32)       在Object.Module._extensions..js(module.js:579:10)       在Module.load(module.js:487:32)       在tryModuleLoad(module.js:446:12)       在Function.Module._load(module.js:438:3)module.js:471       扔错了;       ^

     

错误:无法找到模块' ./ routes / FtseData'       在Function.Module._resolveFilename(module.js:469:15)       在Function.Module._load(module.js:417:25)       在Module.require(module.js:497:17)       at require(internal / module.js:20:19)       在对象。 (/var/app/current/routes.js:7:20)       在Module._compile(module.js:570:32)       在Object.Module._extensions..js(module.js:579:10)       在Module.load(module.js:487:32)       在tryModuleLoad(module.js:446:12)       在Function.Module._load(module.js:438:3)module.js:471       扔错了;       ^

这是我的server.js文件

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 个答案:

答案 0 :(得分:3)

我的文件是/routes/FtseData.js

导致错误

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

匹配文件所需的案例

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