节点与节点之间的通信 c#
You can have different configurations for production and development environments.
您可以为生产和开发环境使用不同的配置。
Node assumes it’s always running in a development environment. You can signal Node.js that you are running in production by setting the NODE_ENV=production
environment variable.
Node假定它始终在开发环境中运行。 您可以通过设置NODE_ENV=production
环境变量来向Node.js发出正在生产中运行的信号。
This is usually done by executing the command
通常通过执行命令来完成
export NODE_ENV=production
in the shell, but it’s better to put it in your shell configuration file (e.g. .bash_profile
with the Bash shell) because otherwise the setting does not persist in case of a system restart.
在shell中,但是最好将其放入您的shell配置文件(例如,带有Bash shell的.bash_profile
)中,因为否则在系统重启时该设置将不会保留。
You can also apply the environment variable by prepending it to your application initialization command:
您还可以通过将环境变量放在应用程序初始化命令之前来应用它:
NODE_ENV=production node app.js
This environment variable is a convention that is widely used in external libraries as well.
此环境变量是一个约定,在外部库中也广泛使用。
Setting the environment to production
generally ensures that
设置production
环境通常可以确保
- logging is kept to a minimum, essential level 日志记录保持在最低水平
- more caching levels take place to optimize performance 发生更多的缓存级别以优化性能
For example Pug, the templating library used by Express, compiles in debug mode if NODE_ENV
is not set to production
. Express views are compiled in every request in development mode, while in production they are cached. There are many more examples.
例如,如果未将NODE_ENV
设置为production
,则Express使用的模板库Pug会以调试模式进行编译。 Express视图在开发模式下的每个请求中都进行编译,而在生产环境中则将其缓存。 还有更多示例。
Express provides configuration hooks specific to the environment, which are automatically called based on the NODE_ENV variable value:
Express提供了特定于环境的配置挂钩,这些挂钩根据NODE_ENV变量值自动调用:
app.configure('development', () => {
//...
})
app.configure('production', () => {
//...
})
app.configure('production', 'staging', () => {
//...
})
For example you can use this to set different error handlers for different mode:
例如,您可以使用它为不同的模式设置不同的错误处理程序:
app.configure('development', () => {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
})
app.configure('production', () => {
app.use(express.errorHandler())
})
节点与节点之间的通信 c#