Node.js Is there a synchronous version of the http.get method in node.js?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Node.js does not provide a built-in synchronous http.get. Its I/O model is fundamentally asynchronous and non-blocking. To make HTTP requests that "feel" synchronous, use async/await with the native fetch API (Node 18+), the node-fetch package, or the axios library. For scripts that truly need synchronous HTTP (blocking the event loop), the sync-rpc or execSync workaround exists but is strongly discouraged for production use because it blocks the entire event loop.
Why There Is No Synchronous http.get
Node.js is built on a single-threaded event loop. A synchronous HTTP request would block the entire process — no other requests, timers, or callbacks could execute until the response arrives. This defeats Node.js's core design advantage.
Solution 1: async/await with fetch (Node 18+)
Node 18+ includes the global fetch API:
await pauses the async function until the promise resolves, making the code read like synchronous code while remaining non-blocking.
Solution 2: async/await with node-fetch (Node < 18)
Solution 3: async/await with axios
Solution 4: Promisifying http.get
Wrap Node's built-in http.get in a promise:
Solution 5: Top-Level await (ES Modules)
In Node 14.8+ with ES modules, you can use await at the top level:
Truly Synchronous HTTP (Not Recommended)
If you absolutely need blocking HTTP (e.g., in a CLI script where event loop is not needed):
Or use the sync-request package:
Both approaches block the entire Node.js process and should only be used in one-off scripts, never in servers.
Comparison
| Approach | Blocking | Dependencies | Node Version |
fetch + async/await | No | None | 18+ |
node-fetch + async/await | No | node-fetch | Any |
axios + async/await | No | axios | Any |
Promisified http.get | No | None | Any |
execSync('curl ...') | Yes | curl installed | Any |
sync-request | Yes | sync-request | Any |
Common Pitfalls
- Blocking the event loop with synchronous HTTP: Using
sync-requestorexecSyncin a web server blocks ALL incoming requests while waiting for the HTTP response. A single slow external API call can make your server unresponsive. Always use async/await in servers. - Forgetting to await:
const data = fetch(url)returns a Promise, not the data. Withoutawait, you getPromise { <pending> }instead of the response. Always useawait fetch(url)inside anasyncfunction. - Unhandled promise rejections: If
fetchfails (network error, timeout) and you do not catch the error, Node.js logs anUnhandledPromiseRejectionwarning. Always wrapawaitcalls intry/catchblocks. fetchnot available in older Node versions: The globalfetchwas added in Node 18 (experimental in 17). On older versions, usenode-fetchoraxios. Check your Node version withnode --version.- Not handling HTTP error status codes:
fetchdoes not throw on 4xx/5xx responses —response.okisfalsebut no exception is thrown. Always checkresponse.okorresponse.statusbefore parsing the body.
Summary
- Node.js has no synchronous
http.get— useasync/awaitfor synchronous-looking code - Use
fetch(Node 18+) oraxiosfor the cleanest async HTTP - Wrap callbacks in Promises to use
awaitwith older APIs - Never use synchronous HTTP in production servers — it blocks the event loop
- Use
try/catchwithawaitto handle network errors and non-2xx responses
Related reading
- Node.js quick file server (static files over HTTP)
- NodePort services not available on all nodes
- Non-blocking queue of HTTP POST requests with persistence
- Not able to connect to kafka server on google compute engine from local machine
- Node.js maxing out at 1000 concurrent connections
- node.js resolve promise and return value
- node.js never exits after insert to couchbase, opposite of most node questions
- node.js node-cassandra-client request failing

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.