Treat modules as contracts
Choose a consistent module boundary for a beginner Node.js project.
The move: choose one module contract for your own code. CommonJS and ESM can both be valid in Node.js. The trouble starts when a codebase uses one style in one file, another style in a helper, and no clear declaration in package.json. CommonJS contract CommonJS code usually reads with require() and publishes with module.exports or exports.name. It is common in older Node.js projects and many packages. ESM contract ESM code uses import and export. In Node.js, ESM behavior depends on file extensions and package settings such as type: "module". Boundary discipline Do not treat import errors as random. Ask: what…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in