Node-config won't use variables from custom-environment-variables.json in Heroku
我正在使用node-config模块获取mongo连接字符串和jwt密钥。
例如:
1 2 | if(!config.get('jwtPrivateKey')){ throw new Error('FATAL ERROR: jwtPrivateKey is not defined'); |
我的
1 2 3 4 | { "jwtPrivateKey":"video-app_jwtPrivateKey", "db":"video-app_db" } |
1 2 3 4 | { "db":"default db", "jwtPrivateKey":"default key" } |
1 2 3 4 | { "db":"production db", "jwtPrivateKey":"production key" } |
长话短说-尽管环境变量是在heroku中设置的,但node-config不会查看在
相矛盾
我有同样的问题。从heroku的键中删除了连字符,以便从自定义环境变量读取数据。
so custom-environment-variables.json:
1 2 3 4 | { "jwtPrivateKey":"video-app_jwtPrivateKey", "db":"video-app_db" } |
成为:
1 2 3 4 | { "jwtPrivateKey":"videoapp_jwtPrivateKey", "db":"videoapp_db" } |
Heroku文档:
Config var policies
- Config var keys should use only alphanumeric characters and the underscore character (_) to ensure that they are accessible from all
programming languages. Config var keys should not include the hyphen
character.- Config var data (the combination of all keys and values) cannot exceed 32kb for each app.
- Config var keys should not begin with a double underscore (__).
- A config vara€?s key should not begin with HEROKU_ unless it is set by the Heroku platform itself.
您可以在Heroku中以这种方式配置vars
因此,我遇到了同样的问题:我部署了我的应用程序,在Heroku中设置了环境变量,但是没有任何效果(不同于本地机器,一切正常)。
似乎问题出在我不小心将所有
我所做的对我有用:
我从git中删除了
1 | git rm -rf node_modules |
然后提交并推送。
这是我收到的错误消息:
Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
我花了两天时间试图弄清楚。
希望对您有所帮助。