NODE_ENV无法识别为内部或外部命令 [英] NODE_ENV is not recognised as an internal or external command

查看:223
本文介绍了NODE_ENV无法识别为内部或外部命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js进行开发,并且希望同时考虑生产和开发环境.我发现在运行node.js服务器时设置NODE_ENV可以完成这项工作.但是,当我尝试在package.json脚本中设置它时,出现了以下错误:

I am developing in node.js and wanted to take into account both production and development environment. I found out that setting NODE_ENV while running the node.js server does the job. However when I try to set it in package.json script it gives me the error:

NODE_ENV无法识别为内部或外部命令

NODE_ENV is not recognised as an internal or external command

下面是我的package.json

Below is my package.json

{
  "name": "NODEAPT",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "NODE_ENV=development node ./bin/server",
    "qa2": "NODE_ENV=qa2  node ./bin/server",
    "prod": "NODE_ENV=production node ./bin/server"
  },
  "dependencies": {
    "body-parser": "~1.15.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "express": "~4.13.4",
    "fs": "0.0.1-security",
    "jade": "~1.11.0",
    "morgan": "~1.7.0",
    "oracledb": "^1.11.0",
    "path": "^0.12.7",
    "serve-favicon": "~2.3.0"
  }
}

我将节点服务器运行为:例如npm run qa2.

I run my node server as: npm run qa2 for example.

我不知道我在做什么错.感谢您的帮助

I don't know what I am doing wrong. Any help is appreciated

推荐答案

由于您使用的是windows operating system.,因此该命令与您使用的unix系统命令有所不同.

Since you are using windows operating system., the command varies from the unix system command that you are using.

在Windows中,您必须将脚本修改为.

In windows you have to modify you script as.

"scripts": {
    "start": " SET NODE_ENV=development &  node ./bin/server",
    "qa2": "SET NODE_ENV=qa2 & node ./bin/server",
    "prod": "SET NODE_ENV=production & node ./bin/server"
  },

使用SET,然后使用&.

但是建议使用cross-env npm软件包来确保跨平台稳定性.

However using cross-env npm package for cross platform stability is recommeded.

npm install -S cross-env

"scripts": {
    "start": " cross-env NODE_ENV=development &  node ./bin/server",
    "qa2": "cross-env NODE_ENV=qa2 & node ./bin/server",
    "prod": "cross-env NODE_ENV=production & node ./bin/server"
  },

这篇关于NODE_ENV无法识别为内部或外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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