如何在 Windows 上设置 NODE_ENV=production? [英] How can I set NODE_ENV=production on Windows?

查看:37
本文介绍了如何在 Windows 上设置 NODE_ENV=production?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ubuntu 中很简单;我可以使用以下方式运行应用程序:

In Ubuntu it's quite simple; I can run the application using:

$ NODE_ENV=production node myapp/app.js

但是,这在 Windows 上不起作用.有没有可以设置属性的配置文件?

However, this doesn't work on Windows. Is there a configuration file where I can set the attribute?

推荐答案

当前版本的 Windows 使用 Powershell 作为默认 shell,因此使用:

Current versions of Windows use Powershell as the default shell, so use:

$env:NODE_ENV="production"

根据下面@jsalonen 的回答.如果您使用 CMD(不再维护),请使用

Per @jsalonen's answer below. If you're in CMD (which is no longer maintained), use

set NODE_ENV=production

这应该在您打算运行 Node.js 应用程序的命令提示符中执行.

This should be executed in the command prompt where you intend to run your Node.js application.

上面的行将为您执行命令的命令提示符设置环境变量 NODE_ENV.

The above line would set the environment variable NODE_ENV for the command prompt where you execute the command.

要全局设置环境变量,使其在单个命令提示符之外持续存在,您可以从控制面板"的系统"中找到该工具(或在开始菜单的搜索框中键入环境").

To set environment variables globally so they persist beyond just the single command prompt, you can find the tool from System in Control Panel (or by typing 'environment' into the search box in the start menu).

这篇关于如何在 Windows 上设置 NODE_ENV=production?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆