Easy javascript

Export and require a utility

Problem

Simulate CommonJS: export add function and use it.

Hints
  • module.exports = { add }

Your practice code

Ready — edit the code above and click Run.

Solution

function add(a, b) { return a + b; }
module.exports = { add };
const { add: addFn } = module.exports;
console.log(addFn(2, 3));

Try solving on your own first, then reveal the official answer.

Explanation

CommonJS vs ESM is a frequent Node interview question—know both syntaxes.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details