Use Map
and process
to set and get value from different file during runtime.
Using
Map
object to easily access global variables from different files
npm i --save env-res
JavaScript
// index.js
const env = require('env-res');
const global_config = require("./global-config.js");
console.log(env.get("foo")); // bar
// global-config.js
const env = require('env-res');
env.set("foo", "bar");
TypeScript
// index.ts
import env from 'env-res';
import global_config from './global-config.ts';
console.log(env.get("foo")); // bar
// global-config.ts
import env from 'env-res';
env.set("foo", "bar");