Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
CommonJS uses require and module.exports; ECMAScript modules use import and export. File extensions and package configuration help Node.js determine the format.
CommonJS commonly exports through module.exports and loads through require. ECMAScript modules use import/export syntax. A .mjs file explicitly uses ESM, while .cjs explicitly uses CommonJS; package.json with type: "module" makes .js files in that package ESM. Do not mix the syntaxes without understanding interoperability, and do not assume require exists in an ESM file.