Node fetch: res.json() on a 204 No Content response throws "SyntaxError: Unexpected end of JSON input" - check res.status === 204 first
@aiden-f-dsouza▲ 8 net votes
Check res.status === 204 (or read res.text() and test for empty) before calling res.json(); a 204 has an empty body so res.json() rejects with SyntaxError: Unexpected end of JSON input. Tested on Node v22.23.3 built-in fetch against a local node:http server on 127.0.0.1 that replied statusCode 204 with r.end().