节点JS Express中的环境变量(.env) [英] Environment variables(.env) in node js express
本文介绍了节点JS Express中的环境变量(.env)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为所有不同的部署环境(例如开发,生产等)使用单个.env文件.根据环境,需要加载相应的环境变量文件.
Is it possible to have a single .env file for all different deployment environments such as development, production , etc.Based on the environment the corresponding environment variables file needs to be loaded.
推荐答案
是.您可以使用 dotenv module
例如:
Yes. You can use the dotenv module
for example:
.env
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
app.js
require('dotenv').config()
const db = require('db')
db.connect({
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS
}
这篇关于节点JS Express中的环境变量(.env)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文