CommonJS

The CommonJS module specification is the standard used in Node.js. In the CommonJS module system, each file is treated as a separate module.

const addFive = function (x) {
  return x + 5;
};

const phone = { Apple: "IPhone", Samsung: "Galaxy" };

module.exports = {
  addFive,
  phone,
};
const lib = require("./lib.js");

console.log(lib.addFive(5));
console.log(lib.phone.Apple);
console.log(lib.phone.Samsung);
10
IPhone
Galaxy

https://nodejs.org/api/modules.html

Leave a Reply

Your email address will not be published.

ANOTE.DEV