Commit 3f43d4c6 authored by Vadym Gidulian's avatar Vadym Gidulian

Added `checkEnvironmentVariables` function

parent c2b8c4e0
'use strict'; 'use strict';
const grace = require('./grace'); const {checkEnvironmentVariables} = require('./util');
const {createError, logError, logInfo, logWarn} = require('./log');
['MONGODB_URI', 'SEQID_GEN_API'].forEach(varname => { checkEnvironmentVariables('MONGODB_URI', 'SEQID_GEN_API');
if (!process.env[varname]) {
logError(`Environment variable ${varname} is not defined!`);
grace.shutdown(1);
}
});
const {MongoClient} = require('mongodb'); const {MongoClient} = require('mongodb');
const SeqidGenApi = require('@gviagroup/seqid-gen-api'); const SeqidGenApi = require('@gviagroup/seqid-gen-api');
const grace = require('./grace');
const {createError, logError, logInfo, logWarn} = require('./log');
let mongoClient = null; let mongoClient = null;
const seqidGen = new SeqidGenApi(process.env.SEQID_GEN_API); const seqidGen = new SeqidGenApi(process.env.SEQID_GEN_API);
......
'use strict'; 'use strict';
const {shutdown} = require('./grace');
const {logError} = require('./log');
module.exports = { module.exports = {
checkEnvironmentVariables(...varNames) {
for (const varName of varNames) {
if (!process.env[varName]) {
logError(`Environment variable ${varName} is not set!`);
shutdown(1);
}
}
}
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment