This package provides a synchronous HTTP request utility for Node.js, built on top of `urllib` and utilizing Node.js's `spawnSync` module to achieve blocking I/O. The current stable version is 1.1.4, and it has not been updated in approximately nine years, indicating it is no longer maintained. Its primary function is to perform HTTP requests that halt the Node.js event loop until a response is received, a pattern generally considered an anti-pattern in asynchronous Node.js environments. Key differentiators include its explicit synchronous operation, contrasting with the typically non-blocking nature of Node.js. It explicitly states support only for Node.js v0.11.13+ and does not support features like response streams or custom HTTP agents, limiting its utility for modern applications requiring efficient handling of large data or complex network interactions.
npm install urllib-syncVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to make a basic synchronous GET request using `urllib-sync`. It fetches content from a URL and logs the status, headers, and a snippet of the response body. It highlights the blocking nature of the request and provides commented-out examples for POST requests and options.
Do not use `urllib-sync` in modern Node.js applications. Prefer native `fetch` (Node.js v18+) or packages like `node-fetch`, `axios`, or the original `urllib` (which is asynchronous) for non-blocking HTTP requests.
Always use asynchronous HTTP request libraries (e.g., `fetch`, `axios`, `urllib`'s async methods) to maintain a non-blocking event loop. Refactor code to use `async/await` or Promises.
For stream support or custom agents, you must use an asynchronous HTTP client like `urllib` (the non-sync version), `node-fetch`, or `axios`.
Migrate to actively maintained asynchronous HTTP clients to ensure security, compatibility, and access to modern features and performance optimizations.
This package is incompatible with modern Node.js. Update your application to use asynchronous HTTP clients instead of `urllib-sync`.
urllib-sync is a CommonJS package. Either refactor your project to use CommonJS modules or migrate your HTTP requests to a modern, ESM-compatible asynchronous library like `node-fetch` or native `fetch`.
Ensure you are destructuring the `request` function correctly: `const { request } = require('urllib-sync');` or accessing it as a property: `const request = require('urllib-sync').request;`