gpt4 book ai didi

mysql - 为不同环境配置不同 Node MySQL连接

转载 作者:行者123 更新时间:2023-11-29 07:59:26 25 4
gpt4 key购买 nike

我有 3 个不同的 MySQL 数据库连接,具体取决于环境(本地、开发和实时)。

使用node-mysql,如何提供正确的连接详细信息或检测正在使用的环境?

最佳答案

process.env.NODE_ENV 变量是存储值的位置。

你可以这样做:

if (process.env.NODE_ENV == 'production') 

或者这是内置于 app.configure 函数中的

app.configure('development', function(){

});

app.configure('production', function(){

...
});

从命令行设置变量

Linux:

$ echo export NODE_ENV=production >> ~/.bash_profile
$ source ~/.bash_profile

Windows:

set NODE_ENV=production
setx NODE_ENV production

关于mysql - 为不同环境配置不同 Node MySQL连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24268377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com