SAP-BTP-Spielwiese/app1/node_modules/@sap/xsenv/lib/loadEnv.js
Markus Rettig 775ac7b58c completed step 3 from the tutorial
you must login with an BTP account in order to see the app
2024-02-08 16:13:36 +01:00

32 lines
776 B
JavaScript

'use strict';
var fs = require('fs');
var debug = require('debug')('xsenv');
var VError = require('verror');
module.exports = loadEnv;
function loadEnv(jsonFile) {
jsonFile = jsonFile || 'default-env.json';
if (!fs.existsSync(jsonFile)) {
return;
}
debug('Loading environment from %s', jsonFile);
try {
var json = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
} catch (err) {
throw new VError(err, 'Could not parse %s', jsonFile);
}
for (var key in json) {
if (key in process.env) {
continue; // do not change existing env vars
}
var val = json[key];
// env vars hold only strings
if (typeof val === 'object') {
process.env[key] = JSON.stringify(val);
} else {
process.env[key] = val + '';
}
}
}