Categories
JavaScript Answers

How to call Node.js “require” function and parameters?

Spread the love

To call Node.js "require" function and parameters, we export a function.

For instance, we write

module.exports = (options) => {
  const app = options.app;
  const param2 = options.param2;
};

in lib.js to export a function.

Then we write

require("lib.js")({ app, param2 });

to require the lib.js file and call the function that’s imported.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *