Architecture

Migration planning

A runtime migration is an evidence-led transition between supported Node versions, module systems or dependency contracts. Separate changes to reduce the number of possible failure causes. Inventory runtime flags, dependencies, native addons, module mode, CLI entry points and supported environments. For CommonJS-to-ESM, mark files explicitly using .mjs/.cjs or package type. Replace require and exports deliberately; ESM relative imports normally need extensions. Native addon ABI compatibility, Express routing changes and TypeScript build configuration need their own tests. Run existing contract tests before and after each change and maintain rollback compatibility with persistent data. Do not combine a major runtime upgrade, framework migration and database schema rewrite into one untested release.

Formal Syntax & Structure

nodejs syntaxnodejs
Conceptual contract; see example

Working Example

Example Snippetnodejs
import {writeFileSync} from 'node:fs';import {createRequire} from 'node:module';writeFileSync('legacy.cjs','module.exports={total:(a,b)=>a+b}');writeFileSync('modern.mjs','export const total=(a,b)=>a+b;');const require=createRequire(import.meta.url);const legacy=require('./legacy.cjs');const modern=await import('./modern.mjs');console.log(legacy.total(2,3),modern.total(2,3));
Node.js Reference