Centra is a lightweight, promise-based HTTP client specifically designed for Node.js environments. It emphasizes a minimal API surface while providing core functionalities like JSON/form body sending, query parameters, custom headers, timeouts, and response streaming. Currently at version 2.7.0, Centra focuses on developer control and efficiency, offering a lean alternative to more feature-rich clients like Axios or Node-fetch. Its primary differentiator is its small footprint and direct interaction with Node's built-in `http` and `https` modules, making it suitable for performance-critical applications or environments where bundle size is a concern. While it provides a fluent API for common tasks, it also allows direct modification of Node's core HTTP request options for advanced use cases. Release cadence appears to be on-demand rather than fixed, with updates driven by feature needs and bug fixes.
npm install centraVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic GET and POST requests, sending a JSON body, setting a timeout, and streaming a file download using Centra.
Use `const centra = require('centra')` in CommonJS modules. For ES Modules, consider using a dynamic `import('centra')` or a build step to transpile your code, or ensure your `package.json` does not have `"type": "module"` if intending to use CJS libraries directly.Always chain a `.timeout(milliseconds)` call before `.send()` to prevent requests from hanging. Example: `centra(url).timeout(5000).send()`.
To enable redirect following, use the `.followRedirects(maxRedirects)` method, specifying the maximum number of redirects to follow. Example: `centra(url).followRedirects(5).send()`.
Carefully consult Node.js `http.request` documentation before using `.option()`. Always validate the impact of custom options on connection security, certificates, and agent behavior, especially in production environments.
After `await centra(...).send()`, always check `if (res.statusCode >= 400) { // handle error }`.Rename your file to `.cjs` or ensure your `package.json` does not have `"type": "module"` if you intend to use CommonJS. Alternatively, if Node.js 22+ is used, an experimental flag `--experimental-require-module` might allow synchronous `require` of ESM, but `centra` is CJS itself. The most robust fix is to use `const centra = require('centra')` in a CJS context.Ensure you are importing the package as a default function: `const centra = require('centra')`. Centra itself is the function.Add a `.timeout(milliseconds)` call to your request chain to ensure requests have a maximum duration. For example, `centra(url).timeout(10000).send()` for a 10-second timeout.
Always wrap your `await centra(...).send()` calls in a `try...catch` block within an `async` function, or chain a `.catch(error => { /* handle error */ })` to the promise.No dependency data recorded yet.