Node.js scripting with ES modules and CommonJS, stdlib-first, npm conventions, and async/await patterns. Use when writing Node.js scripts, .js or .mjs files, working with npm, or building CLI tools.
Node.js scripting with ES modules and CommonJS, stdlib-first, npm conventions, and async/await patterns. Use when writing Node.js scripts, .js or .mjs files, working with npm, or building CLI tools.
Node.js
Module System
Prefer ES modules (.mjs) for new scripts: import/export syntax, top-level await
Use CommonJS (.js) when compatibility with older Node.js or existing codebases is needed
Always specify "type": "module" in package.json for ES module directories
Use .mjs extension to explicitly opt into ES modules regardless of package.json
Stdlib First
Node.js has a RICH standard library - use it before reaching for npm packages