To add global variables for Node.js standard modules, we export the variables.
For instance, we write
const common = {
util: require("util"),
fs: require("fs"),
path: require("path"),
};
module.exports = common;
to export the common
object by setting it as the value of module.exports
in common.js.
Then we write
const common = require("./common.js");
console.log(common.util.inspect(common));
to call require
to include the exports in common.js in our code.