# node问题集锦
# 1. 当前根路径下某文件的路径
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
console.log(resolve('src/utils'));
1
2
3
4
5
6
2
3
4
5
6
# 2. 在node中引入文件
// config.js
const ahUrl = "http://xxx:9200"
// 提供给node的常量
module.exports = {
ahUrl,
}
// 外部引入
const config = require('./config');
// console.log(config.ahUrl);
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
~End~