1// Use require.main.require to get a module from the root folder.
2const Globals = require.main.require("./globals.js");
3const YourCustomModule = require("./yourmodule.js");
4
5console.log(YourCustomModule.message);
6
7// --- yourmodule.js ---
8module.exports = {
9 message: "Hello World!",
10 otherData: "Hello Grepper!"
11};
1//What is require in Nodejs?
2//Node.js follows the CommonJS module system, and the builtin require
3//function is the easiest way to include modules that exist in separate
4//files. The basic functionality of require is that it reads a JavaScript
5//file, executes the file, and then proceeds to return the exports object.
6