From f2015414e2147745907e84ebc579430343485f0a Mon Sep 17 00:00:00 2001 From: filesite-io Date: Tue, 4 Jun 2024 21:27:56 +0800 Subject: [PATCH] add env variable support --- server.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server.mjs b/server.mjs index 2e75a82..0b0852b 100644 --- a/server.mjs +++ b/server.mjs @@ -3,10 +3,17 @@ import Monitor from './monitor.mjs'; (async () => { let configFile = 'config.json'; + + //命令行参数支持,格式:npm start -- my_config.json if (process.argv.length >= 3) { configFile = process.argv[2]; } + //环境变量支持,格式:CONFIGFILE=my_config.json pm2 start server.mjs + if (typeof(process.env.CONFIGFILE) != 'undefined') { + configFile = process.env.CONFIGFILE; + } + let monitor = new Monitor(configFile); await monitor.init(); })(); \ No newline at end of file