Developer reference

Short developer docs. Each one answers one question, with code you can copy.

Categories

Recently added

Fix "Cannot find module" with ES modules in Node.js
Node.js Node.js ES modules require explicit file extensions in import paths.
Undo the last commit but keep the changes
Git Reset the last commit while keeping all changes staged and ready to re-commit.
Array reduce: sum values and transform objects
JavaScript Array.reduce() iterates an array and accumulates a single result.
Find what fills the heap when type-aware ESLint runs out of memory
TypeScript Measure the heap each folder leaves behind, then give each TypeScript program its own ESLint process.
Insert text at the selection in ProseMirror without breaking select-all or image selections
JavaScript To put text where the user's selection is from code (dictation, snippets, autocomplete), call tr.insertText(text) with no positions, and give block selections a textblock first.
Fastify route runs after a hook already sent a reply
Node.js A preHandler or onRequest hook sends a 401, 403 or 429, but the route handler runs anyway, crashes on missing state, and Fastify logs FST_ERR_REP_ALREADY_SENT and ERR_HTTP_HEADERS_SENT.
Why useEffect runs twice in development and how to write it so that's fine
React In development, Strict Mode mounts each component, unmounts it, and mounts it again, so an effect runs, cleans up, and runs once more.
Stash work in progress including new, untracked files
Git git stash alone leaves new files behind.
Check an object against a type without losing its literal types
TypeScript Use satisfies when you want the compiler to check a value against a type but keep the narrower type it inferred.
Run a TypeScript file with node and no build step
Node.js Current Node runs .ts files by stripping the type annotations.