How do you create a custom Node.js module? You can make any .js file a reusable module by exporting functions, objects, or classes using module.exports. 📦 Step-by-step example: mathUtils.js — Custom module function add(a, b) { return a + b; } function subtract(a, b) { return a - b; } module.exports = { add, subtract };
pp.js — Use the custom module
const math = require('./mathUtils');
console.log(math.add(5, 3)); // Output: 8
console.log(math.subtract(10, 4)); // Output: 6
✅ This pattern helps you break code into organized, testable, and reusable pieces — just
like using built-in or third-party libraries.
dvanced Node.js Concepts