{"dataset":{"id":"00000000-0000-0000-0000-000000000007","slug":"nodejs-best-practices","name":"Node.js best practices","description":"Source-linked guidance on Node.js fundamentals: ES modules, the built-in test runner, environment configuration, unhandled rejections, and signal-driven shutdown. Scoped to current Node.js LTS; not a general JavaScript corpus.","visibility":"public","version":1,"documentCount":5,"publisher":"Koskamo editorial","license":"Original summaries; linked sources retain their own terms.","reviewedAt":"2026-10-04T00:00:00.000Z","readOnly":true,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},"total":5,"documents":[{"title":"Graceful shutdown on POSIX signals","sourceUrl":"https://nodejs.org/api/process.html","text":"A Node.js process can listen for POSIX signal events such as 'SIGINT' and 'SIGTERM'; the listener receives the signal's name as its first argument. On SIGTERM, stop accepting new connections, let in-flight work finish, close servers and handles, and then exit; that shutdown sequence is Koskamo editorial guidance, not a Node.js requirement. Scope: current Node.js LTS. Reviewed October 4, 2026.","id":"nodejs-best-practices:Graceful shutdown on POSIX signals","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Unhandled promise rejections","sourceUrl":"https://nodejs.org/api/process.html","text":"When a promise rejects without a rejection handler, Node.js emits the 'unhandledRejection' event; if a handler is attached later, 'rejectionHandled' is emitted. With no 'unhandledRejection' listener, the default behavior exits the process with a non-zero exit code and prints the stack trace. Do not attach a listener that swallows rejections to keep a broken process alive; let the process fail and restart it under a supervisor. That recommendation is Koskamo editorial guidance. Scope: current Node.js LTS. Reviewed October 4, 2026.","id":"nodejs-best-practices:Unhandled promise rejections","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Environment configuration with process.env and --env-file","sourceUrl":"https://nodejs.org/api/cli.html","text":"Read environment variables from process.env. Node.js can load a file of KEY=value pairs at startup with --env-file=file; the --env-file-if-exists variant does the same without throwing when the file is missing. Keep env files carrying secrets out of version control and treat missing required variables as a startup error; both practices are Koskamo editorial guidance, not Node.js requirements. Scope: current Node.js LTS. Reviewed October 4, 2026.","id":"nodejs-best-practices:Environment configuration with process.env and --env-file","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Built-in test runner","sourceUrl":"https://nodejs.org/api/test.html","text":"Node.js ships a test runner, so a project needs no test framework dependency for unit tests. Import test, or the describe and it aliases, from node:test and assertions from node:assert, then run node --test to execute the matching test files. Prefer the built-in runner for new projects and reach for an external framework only when its features are actually needed; that preference is Koskamo editorial guidance. Scope: current Node.js LTS. Reviewed October 4, 2026.","id":"nodejs-best-practices:Built-in test runner","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"ECMAScript modules in Node.js","sourceUrl":"https://nodejs.org/api/esm.html","text":"Node.js treats a file as an ES module when it has the .mjs extension, when the nearest package.json sets \"type\": \"module\", or when --input-type=module applies to STDIN input. Use import and export in those files; relative import specifiers must include the full file extension. __filename and __dirname do not exist in ES modules; use import.meta.filename and import.meta.dirname (or import.meta.url) instead. The .cjs extension marks CommonJS explicitly. Prefer ES modules for new code and keep CommonJS for interop with older packages; that preference is Koskamo editorial guidance. Scope: current Node.js LTS. Reviewed October 4, 2026.","id":"nodejs-best-practices:ECMAScript modules in Node.js","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"}]}