给node换盘符_Node.js中环境的切换

在开发过程中我们经常会遇到开发环境和生产环境中有一些环境变量不同。

所以我们需要配置一些环境变量允许你的应用程序根据你想让它们运行的环境做出不同的行为。

所以当我们配置好了环境变量后我们就可以在一套代码中在任意的环境中运行了。

通常我们会在http端口,文件路径,数据库终于到需要切换的情况。

我们新建一个config目录创建development.js, production.js和index.js

image.png

在development.js我们随便写一个路径

module.exports = {

path: {

downloadPath: 'C:\\Users\\XiGong\\Downloads\\'

}

}

在index.js中判断

var path = require('path');

// 通过NODE_ENV来设置环境变量,如果没有指定则默认为生产环境

var env = process.env.NODE_ENV || 'production';

env = env.toLowerCase();

// 载入配置文件

var file = path.resolve(__dirname, env);

try {

var config = module.exports = require(file);

} catch (err) {

console.error('Cannot load config: [%s] %s', env, file);

throw err;

}

接下来我们就可以在任意位置引入了

const config = require('../config');

console.log(config.path.downloadPath)

接下来我们只需要在package.json中修改就可以了

如果是windows环境的话我们需要加上set

例如

"scripts": {

"start": "set NODE_ENV=development&&node bin/www",

"dev": "./node_modules/.bin/nodemon bin/www",

"prd": "pm2 start bin/www",

"test": "echo \"Error: no test specified\" && exit 1"

},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释一下这段代码 def add_seq_to_prefix_tree(self, root_node, cluster: LogCluster): token_count = len(cluster.log_template_tokens) token_count_str = str(token_count) if token_count_str not in root_node.key_to_child_node: first_layer_node = Node() root_node.key_to_child_node[token_count_str] = first_layer_node else: first_layer_node = root_node.key_to_child_node[token_count_str] cur_node = first_layer_node if token_count == 0: cur_node.cluster_ids = [cluster.cluster_id] return current_depth = 1 for token in cluster.log_template_tokens: if current_depth >= self.max_node_depth or current_depth >= token_count: new_cluster_ids = [] for cluster_id in cur_node.cluster_ids: if cluster_id in self.id_to_cluster: new_cluster_ids.append(cluster_id) new_cluster_ids.append(cluster.cluster_id) cur_node.cluster_ids = new_cluster_ids break if token not in cur_node.key_to_child_node: if self.parametrize_numeric_tokens and self.has_numbers(token): if self.param_str not in cur_node.key_to_child_node: new_node = Node() cur_node.key_to_child_node[self.param_str] = new_node cur_node = new_node else: cur_node = cur_node.key_to_child_node[self.param_str] else: if self.param_str in cur_node.key_to_child_node: if len(cur_node.key_to_child_node) < self.max_children: new_node = Node() cur_node.key_to_child_node[token] = new_node cur_node = new_node else: cur_node = cur_node.key_to_child_node[self.param_str] else: if len(cur_node.key_to_child_node) + 1 < self.max_children: new_node = Node() cur_node.key_to_child_node[token] = new_node cur_node = new_node elif len(cur_node.key_to_child_node) + 1 == self.max_children: new_node = Node() cur_node.key_to_child_node[self.param_str] = new_node cur_node = new_node else: cur_node = cur_node.key_to_child_node[self.param_str] else: cur_node = cur_node.key_to_child_node[token] current_depth += 1
03-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值