我的server.js中有以下代码:
throw new Error('The databasenumber was wrong, or you didn\'t bind one.' + process.env.VCAP_SERVICES + " === " + process.env.VCAP_SERVICES["mysql-5.1"]);
此时的输出为:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: The databasenumber was wrong, or you didn't bind one.{"mysql-5.1":[{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]} === undefined
at Object.<anonymous> (/mnt/var/vcap.local/dea/apps/squarific-0-230c9a683dff6b045aa2a237ae9bf515/app/server.js:12:9)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
当然这应该是:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: The databasenumber was wrong, or you didn't bind one.{"mysql-5.1":[{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]} === [{"name":"squarific-data","label":"mysql-5.1","plan":"free","tags":["mysql","mysql-5.1","relational","mysql-5.1","mysql"],"credentials":{"name":"d3d440f0f5eef44ceb9c5e27a94666b58","hostname":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","host":"eu01-user01.cbxizyg0fwcn.eu-west-1.rds.amazonaws.com","port":3306,"user":"uzb6UEDnb5huk","username":"uzb6UEDnb5huk","password":"***"}}]
at Object.<anonymous> (/mnt/var/vcap.local/dea/apps/squarific-0-230c9a683dff6b045aa2a237ae9bf515/app/server.js:12:9)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
不应不确定它的定义,因为您可以清楚地看到[“ mysql-5.1”]实际上是一个数组。
我不知道为什么它会发生这种奇怪的行为,我也找不到任何原因。
最佳答案
service变量将作为JSON字符串而不是appfog的对象传递。
关于javascript - Appfog,nodejs,环境变量:服务不在某一点包含但在另一点包含,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13731246/