如何在OS X中将NODE_ENV设置为生产/开发
问题描述:
用于express.js环境。有什么建议吗?
For use in express.js environments. Any suggestions?
答
在运行您的应用程序之前,您可以在控制台中执行此操作,
Before running your app, you can do this in console,
export NODE_ENV=production
或者如果你在Windows中你可以试试这个:
Or if you are in windows you could try this:
SET NODE_ENV=production
或者你可以像这样运行你的应用程序:
or you can run your app like this:
NODE_ENV=production node app.js
您也可以在js文件中设置它:
You can also set it in your js file:
process.env.NODE_ENV = 'production';
但我建议不要在运行时文件中执行此操作,因为打开它并不容易服务器中的VIM并将其更改为生产。您可以在目录中创建config.json文件,每次运行应用程序时,都会从中读取并设置配置。
But I don't suggest to do it in your runtime file, since it's not easy to open up VIM in your server and change it to production. You can make a config.json file in your directory and everytime your app runs, it reads from it and sets the configuration.