节点JS环境变量和Heroku部署 [英] Node JS environment variables and Heroku deployment

查看:125
本文介绍了节点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.

这篇关于节点JS环境变量和Heroku部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆