To use global variable in Node.js, we create a module.
For instance, we write
module.exports = new Logger(customConfig);
in logger.js to export the Logger
object.
Then we write
const logger = require("./logger");
logger.log("foo");
in app.js to call require
to import the logger.js module and call logger
.