Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.
译文:
Dotenv是一个从.env
文件加载环境变量到process.env
上的零依赖的模块
安装
pnpm i -D dotenv
示例
配置文件
# .env
DATABASE_URL='mysql://root:123456@127.0.0.1/data'
require('dotenv').config(); console.log(process.env.DATABASE_URL); // mysql://root:123456@127.0.0.1/data
ES6
// package.json "type": "module", import 'dotenv/config' console.log(process.env.DATABASE_URL); // mysql://root:123456@127.0.0.1/data