节点JS环境变量和Heroku部署

问题描述:

我有一个使用dotenv包的项目将我的环境变量加载到我的NodeJS应用程序中 我使用以下行

I have a project using the dotenv package to load my environment variables in my NodeJS application I use the following line

var dotenv = require('dotenv').load({ silent: true }); 

//Example of use
username: process.env.CONVERSATION_USERNAME

我现在正计划在Heroku上部署此应用程序.但是,出于某些明显的安全原因,我不想提交.env文件.

I am now planning to deploy this application on Heroku. However, for some obvious security reasons i don't want to commit my .env file.

我是NodeJS的新手,我想知道是否有办法说如果.env文件不存在,请从Heroku加载环境变量"

I'm new to NodeJS and I would like to know if there is a way to say "If the .env file doesn't exists, load the environment variable from Heroku"

谢谢, 阿列克西

请勿将您的.env提交给git(即,它应该在您的.gitignore中).

Do not commit your .env to git (i.e. it should be in your .gitignore).

您可以通过Heroku仪表板或使用heroku config:set(例如)在Heroku上定义环境变量.

You define env vars on Heroku either via your Heroku dashboard, or with heroku config:set, e.g.

heroku config:set CONVERSATION_USERNAME=Alex

有关更多信息,请参见此处.

See here for more information.