VSCode调试NodeJS项目配置环境变量ENV
本文字数 0 | 阅读时长 ≈ 0 分钟
category
技术工具
tags
开发
NodeJS
VSCode
type
Post
slug
vscode-nodejs-yarn-environment
summary
NodeJS运行项目中,支持使用
process.env.VARIABLES 的形式访问系统中的环境变量,生产环境中我们可以直接在操作系统中配置环境变量,而如果在本地开始时,想要修改环境变量而又不改动操作系统我们该怎么做?status
Published
date
Mar 15, 2022
icon
password
起因
NodeJS运行项目中,支持使用
process.env.VARIABLES 的形式访问系统中的环境变量,生产环境中我们可以直接在操作系统中配置环境变量,而如果在本地开始时,想要修改环境变量而又不改动操作系统我们该怎么做?WebStorm
JetBrains 的开发IDE,同著名的IntelliJ IDEA一样有强大的开发功能,配置环境变量也十分简单:
- 右上角运行配置中,点击Edit Configurations,

- 点击环境变量中右侧的小图标

- 点击
+即可添加环境变量,这些变量只会在执行该npm程序时生效

VsCode
- 在项目根目录的.vscode文件夹下,创建或打开
launch.js

- 参考以下方式编辑launch.js
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via Yarn",
"runtimeExecutable": "yarn",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["dev"],
"env":{
"NEXT_PUBLIC_BEI_AN":"测试环境变量",
"NOTION_PAGE_ID":"bee1fccfa3bd47a1a7be83cc71372d83",
"CUSTOM_PARAMS":"foo"
},
}
]
}以上配置代表用
yarn命令,执行dev指令;启动时会将env 下的环境变量传入到nodejs中。- Author:tangly1024
- URL:https://tangly1024.com/article/vscode-nodejs-yarn-environment
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts :
Tags:
开发
NodeJS
VSCode