Home > Web Front-end > JS Tutorial > How to solve the error when setting NODE_ENV in nodejs?

How to solve the error when setting NODE_ENV in nodejs?

青灯夜游
Release: 2021-05-17 10:47:57
forward
1893 people have browsed it

This article will introduce to you the solution to the nodejs setting NODE_ENV error in the windows environment. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to solve the error when setting NODE_ENV in nodejs?

[Recommended study: "nodejs Tutorial"]

When I was looking at the node document today, I saw "Node.js Chapter "The Difference between Development Environment and Production Environment", I encountered some pitfalls when setting up NODE_ENV. I searched the Internet but couldn't find the answer I wanted, so I posted this post to help everyone avoid the pitfalls. The code shown in the document is as follows:

// app.js 文件中的代码
console.log('NODE_ENV的值为:'+process.env.NODE_ENV)
Copy after login
// 终端命令行
NODE_ENV=production node app.js
Copy after login

Run it...

How to solve the error when setting NODE_ENV in nodejs?

##emm, what's going on? Is the official document written wrong? I quickly went online to check what was going on. After some inquiries, I found that the command lines for setting running variables are different for different operating systems. It should be like this under Windows:

set NODE_ENV=production &&  node app.js
Copy after login
Okay, change it. Let’s do it again... At this point, some people may have successfully run it, while others may encounter the following error.

How to solve the error when setting NODE_ENV in nodejs?

What is going on? The reason is that the terminal used is powershell, which does not support the "&&" symbol. The solution is also very simple. Change powershell to Just turn it into cmd. The switching method is as shown in the figure below:

How to solve the error when setting NODE_ENV in nodejs?

How to solve the error when setting NODE_ENV in nodejs?

The final successful operation is like this:

How to solve the error when setting NODE_ENV in nodejs?

Thanks for browsing!

For more programming related knowledge, please visit:

Programming Video! !

The above is the detailed content of How to solve the error when setting NODE_ENV in nodejs?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template