在 Windows 10 中设置环境变量 package.json [英] Setting environment variables package.json in Windows 10

查看:84
本文介绍了在 Windows 10 中设置环境变量 package.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE:正如问题中所解释的,这不是重复的,因为我已经尝试在环境变量之前添加 set 关键字,并且没有解决问题.

UPDATE: As it is explained in the question, this is not a duplicate because I have already tried adding the set keyword before the environment variable and that did not solve the problem.

我正在学习节点并从书中输入示例.第一个例子展示了http"模块如何工作以及如何创建一个服务器来监听请求.在某些时候,本书要求将以下行添加到 package.json 文件的脚本部分:

I am in the process of learning node and typing examples from a book. The first examples deal with showing how the "http" module works and how to create a server to listen to requests. At some point the book asks to add the following line to the scripts section of the package.json file:

"server": "SERVERPORT=3002 节点 ./fiboserver"

"server": "SERVERPORT=3002 node ./fiboserver"

当我尝试使用 npm run server 运行示例时,我收到以下错误消息:

When I try to run the example with npm run server I get the following error message:

'SERVERPORT' 未被识别为内部或外部命令

'SERVERPORT' is not recognized as an internal or external command

网上一直没找到答案,顶多发现可以试试:

I haven't been able to find any answer on the internet, at most I found that I could try:

"server": "设置 SERVERPORT=3002 节点 ./fiboserver"

"server": "set SERVERPORT=3002 node ./fiboserver"

但这也无济于事,唯一的区别是我再次收到命令提示符而不是错误消息,因此显然服务器永远不会运行.

But that doesn't help either, the only difference is that instead of the error message I get the command prompt again so apparently the server is never run.

我相信作者使用的是 Linux 机器,我使用的是 Windows 10 笔记本电脑.

I believe the author used a Linux machine, I am using a Windows 10 laptop.

我非常致力于学习 Node,我的工作是在 Windows 环境中进行的.我相信在 package.json 上设置环境变量很重要,所以我真的可以使用一些帮助来解决这个问题.

I am really committed to learn Node and my line of work is on Windows environments. I believe that setting environment variables on package.json is important so I could really use some help in figuring this out.

谢谢.

推荐答案

在 Windows 上,您必须将设置变量的命令与使用 && 运算符运行服务器的命令分开.话虽如此,你必须做这样的事情:

On Windows you have to separate the command of setting a variable from the one which runs the server with the && operator. That being said, you have to do something like this:

"server": "set SERVERPORT=3002 && node ./fiboserver"

这篇关于在 Windows 10 中设置环境变量 package.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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