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// The require() method is used to load and cache JavaScript modules.
2// So, if you want to load a local, relative JavaScript module into a Node.js application,
3// you can simply use the require() method.
4
5// Example:
6var yourModule = require( "your_module_name" ); //.js file extension is optional
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