弹性beanstalk如何运行nodejs应用程序代码?

时间:2016-12-16 19:37:16

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

我的应用程序在localhost中正常运行,但当我将其提交到其他地方(如aws(或mcs))时,它无法识别lib委托加载路由所需的文件路径。

这是我期望运行的:

> portal@1.0.0 start /home/code/tmp/portal
> NODE_ENV=development nodemon index.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
consign v0.1.2 Initialized in app
+ ./controllers/homeController.js
+ ./routes/routes.js
Ok! Express is running...

以下跟踪是aws发生的情况,看到它无法识别homeController.js文件:

> portal@1.0.0 start /var/app/current
> NODE_ENV=development nodemon index.js

[nodemon] 1.11.0[39m
[nodemon] to restart at any time, enter `rs`[39m
[nodemon] watching: *.*[39m
[nodemon] starting `node index.js`[39m
consign v0.1.2 Initialized in app
+ ./current/
+ ./current/
/var/app/current/app/routes/routes.js:2
    app.get('/',         app.controllers.homeController.index.bind(app.controllers.homeController)); 
                            ^

TypeError: Cannot read property 'homeController' of undefined
    at Function.module.exports (/var/app/current/app/routes/routes.js:2:33)
at Consign.into (/var/app/current/node_modules/consign/lib/consign.js:239:17)
at Object.<anonymous> (/var/app/current/config/express.js:18:6)
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)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/app/current/index.js:1:80)
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)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
[31m[nodemon] app crashed - waiting for file changes before starting...[39m

知道为什么这个环境会弄乱这个应用程序路径吗? 或者aws如何运行此代码?

1 个答案:

答案 0 :(得分:1)

问题发生的原因是Consign lib的this行为。 aws使用的路径被错误处理,因为它有字符串&#39; app&#39; (在/ var /电流/应用/).

我使用整个路径修改了它(process.cwd()+&#39; / app&#39;)。