Stack & Forbidden Constructs
This chapter fixes the runtime, module system, and project layout for JavaScript code, and names the language constructs you must not use. It is conditional: it applies to source files written as ES modules (**/*.mjs) and does not constrain other ecosystems.
Runtime & Modules
Section titled “Runtime & Modules”| Aspect | Rule |
|---|---|
| Runtime | You MUST target Node.js 22 and MAY use its current syntax. |
| Module system | You MUST write ES modules; source files MUST use the .mjs extension. |
| Imports | You MUST use import / export; you MUST NOT use CommonJS require. |
Project Layout
Section titled “Project Layout”You MUST place application modules under ./src/. Runtime configuration MUST live in a single module at ./src/data/config.mjs, so that settings have one well-known location instead of being scattered across the tree.
./src/ ./src/data/config.mjs ...feature modulesForbidden Constructs
Section titled “Forbidden Constructs”The following constructs are prohibited. Each row states the rule and the sanctioned alternative.
| Construct | Rule | Use instead |
|---|---|---|
for / while loops | MUST NOT | array methods (map, filter, reduce, forEach) |
process.argv | MUST NOT | a dedicated configuration module |
fs for risky operations | MUST NOT | guarded, purpose-built helpers |
eval() | MUST NOT | explicit parsing or a lookup table |
.then().catch() chains | SHOULD NOT | async / await |
Iteration MUST be expressed with array methods rather than imperative loops:
// Prohibitedfor( let i = 0; i < items.length; i++ ) { total += items[ i ].price}
// Requiredconst total = items.reduce( ( sum, item ) => sum + item.price, 0 )Asynchronous Control Flow
Section titled “Asynchronous Control Flow”You SHOULD express asynchronous work with async / await rather than promise continuation chains, because linear control flow is easier to read and to trace:
// Discouragedconst load = () => fetchUser().then( ( user ) => render( user ) ).catch( handle )
// Preferredconst load = async () => { const user = await fetchUser() return render( user )}