Node.js, HTTP & APIs
Server runtimes, requests, authentication and API error diagnosis.
72 troubleshooting guides · Page 1 / 3
Does reading a JWT payload prove that its claims are genuine?
Does reading a JWT payload prove that its claims are genuine.
Why is HMAC different from a plain SHA hash?
HMAC combines a message with a secret key so parties sharing that key can check authenticity as well as detect changes.
Why does an async Node.js handler still block every request?
Async functions execute ordinary JavaScript synchronously until they reach an actual asynchronous wait. A large JSON parse, regex or CPU loop still occupies the event loop.
Why does a Node.js download use more memory than the file being transferred?
A producer can enqueue data faster than the destination consumes it. Ignoring stream backpressure allows buffered chunks to accumulate.
How can a Node.js stream chain propagate errors and clean up correctly?
A collection of pipe calls can leave error handling and teardown fragmented across multiple streams. A failure in one stage may leave other stages open.
Why does slicing a Buffer change the original bytes?
A Buffer view can share the same underlying memory. Editing the view then edits the original allocation rather than an independent copy.
Why do UTF-8 characters become corrupted when decoding network chunks separately?
Network chunk boundaries do not align with character boundaries. A multi-byte character can be split across two chunks.
Why does Node.js say require is not defined in ES module scope?
The file is being interpreted as an ES module, where CommonJS globals are not automatically available. File extensions and the nearest package.json type setting influence that interpretation.
Why does a relative import work in a bundler but fail in Node ESM?
Bundlers often add resolution conveniences that Node’s native ES module loader does not apply. A relative import may require the explicit output extension.
How do I locate a data file beside an ES module without relying on cwd?
The working directory belongs to the process launcher, not the module. Services and test runners can start the same code from different directories.
Why does a Node HTTPS Agent not configure built-in fetch connections?
Built-in Node fetch uses Undici rather than the node:https Agent interface. An agent option copied from another HTTP client does not configure its connection dispatcher.
How do I cancel a Node fetch request when its time budget expires?
A request without an explicit deadline can outlive the work that needed it. Cancellation should be passed into the operation rather than implemented only as a competing timer.
Why does a Node timeout scheduled for thirty days fire almost immediately?
Node sets a timeout delay above 2,147,483,647 milliseconds to 1 millisecond. Thirty days exceeds that documented limit; a large future date is not a valid single timer duration.
How should I investigate ECONNRESET without blindly retrying every request?
ECONNRESET means the connection was reset, not that one universal server bug occurred. A peer, proxy, timeout or stale connection can be involved.
Why does Node report that headers were already sent?
The response has already begun, but another code path attempts to change headers or send a second response. Missing returns and competing async callbacks are common causes.
How do I distinguish Node server request, header and keep-alive timeouts?
Different timeouts govern receiving headers, receiving a request and keeping an idle reusable connection open. Changing one does not necessarily bound the full handler runtime.
How can a Node server stop without dropping every in-flight request?
Immediate process exit interrupts active work and can truncate logs or responses. Shutdown needs a bounded draining phase.
Should an application continue normally after an uncaught exception?
An uncaught exception can leave application invariants in an unknown state. Catching it globally and pretending the process is healthy is unreliable.
Why can emitting error on an EventEmitter crash the process?
The error event has special behavior when no listener handles it. It is not just another informational event.
What should I investigate when Node warns about too many event listeners?
The warning often indicates that listeners are added repeatedly without being removed. Increasing the limit can hide a lifecycle leak.
How can Node logs keep the correct request ID across asynchronous calls?
A module-level request ID is shared by concurrent requests and can be overwritten. AsyncLocalStorage provides context associated with an asynchronous execution chain.
When should worker_threads be used instead of asynchronous I/O?
Workers are useful for substantial CPU-intensive JavaScript, while Node’s asynchronous I/O already avoids blocking the main thread for supported operations. Spawning a worker per tiny request adds overhead.
How do spawn and exec differ for a command producing large output?
Exec commonly buffers command output and invokes a shell, while spawn can stream output incrementally with explicit arguments. Large output can exceed buffering limits.
Why is checking fs.exists before opening a file unreliable?
The filesystem can change between the existence check and the operation. This time-of-check/time-of-use gap makes the check neither a permission guarantee nor a safe creation lock.
Ask your own question · Sign in to post questions and answers.