Home > Article > Web Front-end > How to solve the error when setting NODE_ENV in nodejs?
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.
[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)
// 终端命令行 NODE_ENV=production node app.js
Run it...
##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.jsOkay, change it. Let’s do it again... At this point, some people may have successfully run it, while others may encounter the following error. 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: The final successful operation is like this: 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!