simple-get is a minimalist HTTP client library for Node.js, providing the simplest way to make HTTP GET requests with essential features like HTTPS support, automatic redirect following, and gzip/deflate decompression. It focuses on being a lightweight wrapper (under 120 lines of code) around Node.js's native `http` and `https` modules, minimizing overhead. The current stable version is 4.0.1. It maintains a stable API, primarily using callback patterns, and is known for its reliability and efficiency in basic request scenarios. Key differentiators include its small footprint and stream-first approach, making it ideal for scenarios where a full-featured HTTP client is overkill, or when composing with other stream-based utilities.
npm install simple-getVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic GET request using `get.concat` to fetch and parse JSON data from a public API, including error handling for network issues and non-200 responses.
Always pipe or consume the `res` stream: `res.pipe(someStream)` or `res.on('data', ...)`, `res.on('end', ...)`. Alternatively, use `get.concat(url, callback)` to buffer the response automatically.Wrap `simple-get` calls in a Promise. For example: `new Promise((resolve, reject) => get.concat(opts, (err, res, data) => err ? reject(err) : resolve({ res, data })))`.When sending JSON, explicitly set the `Content-Type` header in the `opts` object: `{ headers: { 'Content-Type': 'application/json' }, json: true, body: myObject }`.Verify that the target server is online and listening on the correct IP address and port. Check firewall rules or network connectivity if connecting to a remote host.
Increase the `timeout` option value in milliseconds to allow more time for the request to complete, or investigate why the server is slow to respond. `get({ url: '...', timeout: 5000 }, callback)`Always check for an `err` object first in the callback: `get(opts, function (err, res) { if (err) { /* handle error */ return; } console.log(res.statusCode); });`No dependency data recorded yet.