简体   繁体   English

在 WebStorm 中设置 Node.js 环境变量

[英]Set Node.js environment variables in WebStorm

Is there any way to set environment variables when running a Node.js app using JetBrains' official Node plugin for WebStorm (and their other IDEs as well)?使用 JetBrains 的 WebStorm 官方节点插件(以及他们的其他 IDE)运行 Node.js 应用程序时,有什么方法可以设置环境变量吗?

It is actually possible Here is the official doc: http://www.jetbrains.com/webstorm/webhelp/run-debug-configuration-node-js.html这实际上是可能的这是官方文档: http : //www.jetbrains.com/webstorm/webhelp/run-debug-configuration-node-js.html

Here is my screenshot这是我的截图在此处输入图片说明

No, it's not possible from WebStorm, environment variables should be defined in your system .不,WebStorm 不可能,环境变量应该在您的系统中定义

UPDATE: in the new versions it's possible to set environment variables in the Run/Debug configuration.更新:在新版本中,可以在运行/调试配置中设置环境变量。

I'm new to JetBrains products, i'm not sure if this is the official solution.我是 JetBrains 产品的新手,我不确定这是否是官方解决方案。

Sharing the steps I took resolve this issue.分享我采取的步骤解决了这个问题。

Note: I'm using NPM package manager.注意:我正在使用 NPM package 经理。

In WebStorm menu, go to Run -> Edit Configuration -> click + -> npm在WebStorm菜单中,go Run -> Edit Configuration -> click + -> npm

then provide the following fields:然后提供以下字段:

  • Package.json Package.json
  • Command: run命令:运行
  • Scripts: start脚本:开始
  • Environment: MY_ENV_NAME=123456环境:MY_ENV_NAME=123456

Click Ok点击确定

在此处输入图像描述

Then select the run configuration:然后select的运行配置:

在此处输入图像描述

Finally got the nodejs server up and running:终于启动并运行了 nodejs 服务器: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM