我app.js文件看起來像這樣:的Node.js應用本地工作,但不是在雲
var port = (process.env.VMC_APP_PORT || 3000);
var host = (process.env.VCAP_APP_HOST || 'localhost');
var http = require('http');
var rip = require('./config.js');
http.createServer(function (req, res) {
//do nothing...no response expected via http
}).listen(port, host);
config.js文件包含此(及以上,但削減簡潔/相關性):
//several global.<property_name> assignments
global.mName = "Application Name";
//serveral more global.<property_name> assignments
...
...
require("./main.js");
的main.js文件是這樣開始的:通過運行
console.log(mName+" >>> Loading.");
當我在本地運行的應用程序,它執行罰款:
node app.js
然而,當我推的應用程序中使用以下命令到Cloud Foundry:
vmc push [app_name] --runtime=node06
我收到以下錯誤:
Creating Application: OK Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (10K): OK
Push Status: OK Staging Application 'app_name': OK
Starting Application 'app_name': ..........................Error: Application [app_name] failed to start, logs information below.
====> /logs/stderr.log <====
node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ReferenceError: mName is not defined at Object. (/var/vcap/data/dea/apps/app_name-0-6996d737ed319bcffaf696d653423d7c/app/main.js:6:1) at Module._compile (module.js:411:26) at Object..js (module.js:417:10) at Module.load (module.js:343:31) at Function._load (module.js:302:12) at Array. (module.js:430:10) at EventEmitter._tickCallback (node.js:126:26)
好像我設置的屬性config.js中的全局對象沒有被傳送到main.js。我通過修改main.js來顯式引用global.mName而不僅僅是mName並且錯誤消失了,但是對全局對象屬性的另一個引用然後開始抱怨,我對此進行了驗證。
因爲沒有顯式的「全局」,一切工作正常。參考,我認爲我不應該明確提到「全球」。對於那些變量。有什麼我在這裏失蹤?任何幫助表示讚賞。
謝謝!