惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Docker
GbyAI
GbyAI
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
小众软件
小众软件
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
B
Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2020-08-06 · via 轶哥博客

通过.env文件设置环境变量

通常情况下,.env文件以key/value的键值对的方式存储环境变量。例如:

HOST=0.0.0.0
PORT=80

在前端框架VueReact中均有针对环境变量文件的使用描述。

Node.js或者其它后端项目中,常常会碰到加载环境变量到当前Session的需求。

借助命令

export $(grep -v '^#' .env | xargs -d '\n')

on GNU systems -- or:

export $(grep -v '^#' .env | xargs -0)

on BSD systems(例如MacOS).

参考自:https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-value-pairs

借助Cli工具

npm install -g dotenv-cli

在需要运行的命令前,添加dotenv,例如dotenv yarn start,将会自动加载.env文件中的环境变量到当前命令行上下文。

指定环境变量文件

dotenv -e .env2 <command with arguments>

更多说明:https://github.com/entropitor/dotenv-cli

除特别注明外,本站所有文章均为原创。原创文章均已备案且受著作权保护,未经作者书面授权,请勿转载。