nodejs require file with function code example
Example 1: node import all functions from file
function connect() {
}
function closeConnection() {
}
module.exports = {
connect(),
closeConnection()
};
const DbHelper = require ('./utils/dbHelper');
DbHelper.connect();
const { connect, closeConnection } = require ('./utils/dbHelper');
connect();
Example 2: Node require module
const Globals = require.main.require("./globals.js");
const YourCustomModule = require("./yourmodule.js");
console.log(YourCustomModule.message);
module.exports = {
message: "Hello World!",
otherData: "Hello Grepper!"
};