Skip to content

Commit db5a17e

Browse files
committed
feat(config): expand '~' for BITCORE_CONFIG_PATH
1 parent 7e50bbd commit db5a17e

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

packages/bitcore-node/src/config.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as os from "os";
2-
import parseArgv from "./utils/parseArgv";
3-
import ConfigType from "./types/Config";
4-
let program = parseArgv([], ["config"]);
1+
import { homedir, cpus } from 'os';
2+
import parseArgv from './utils/parseArgv';
3+
import ConfigType from './types/Config';
4+
let program = parseArgv([], ['config']);
55

66
function findConfig(): ConfigType | undefined {
77
let foundConfig;
88
const envConfigPath = process.env.BITCORE_CONFIG_PATH;
99
const argConfigPath = program.config;
10-
const configFileName = "bitcore.config.json";
10+
const configFileName = 'bitcore.config.json';
1111
let bitcoreConfigPaths = [
12-
`${os.homedir()}/${configFileName}`,
12+
`${homedir()}/${configFileName}`,
1313
`../../../../${configFileName}`,
1414
`../../${configFileName}`
1515
];
@@ -21,7 +21,8 @@ function findConfig(): ConfigType | undefined {
2121
for (let path of bitcoreConfigPaths) {
2222
if (!foundConfig) {
2323
try {
24-
const bitcoreConfig = require(path) as { bitcoreNode: ConfigType };
24+
const expanded = path[0] === '~' ? path.replace('~', homedir()) : path;
25+
const bitcoreConfig = require(expanded) as { bitcoreNode: ConfigType };
2526
foundConfig = bitcoreConfig.bitcoreNode;
2627
} catch (e) {
2728
foundConfig = undefined;
@@ -53,10 +54,10 @@ const Config = function(): ConfigType {
5354
maxPoolSize: 50,
5455
pruneSpentScripts: true,
5556
port: 3000,
56-
dbHost: process.env.DB_HOST || "127.0.0.1",
57-
dbName: process.env.DB_NAME || "bitcore",
58-
dbPort: process.env.DB_PORT || "27017",
59-
numWorkers: os.cpus().length,
57+
dbHost: process.env.DB_HOST || '127.0.0.1',
58+
dbName: process.env.DB_NAME || 'bitcore',
59+
dbPort: process.env.DB_PORT || '27017',
60+
numWorkers: cpus().length,
6061
chains: {}
6162
};
6263

@@ -66,13 +67,13 @@ const Config = function(): ConfigType {
6667
Object.assign(config.chains, {
6768
BTC: {
6869
mainnet: {
69-
chainSource: "p2p",
70-
trustedPeers: [{ host: "127.0.0.1", port: 8333 }],
70+
chainSource: 'p2p',
71+
trustedPeers: [{ host: '127.0.0.1', port: 8333 }],
7172
rpc: {
72-
host: "127.0.0.1",
73+
host: '127.0.0.1',
7374
port: 8332,
74-
username: "bitcoin",
75-
password: "bitcoin"
75+
username: 'bitcoin',
76+
password: 'bitcoin'
7677
}
7778
}
7879
}

0 commit comments

Comments
 (0)