Requestify - Node HTTP Client with Caching
Requestify is an HTTP client for Node.js, designed to simplify making HTTP requests and provide built-in caching capabilities. It utilizes the Q promise library for asynchronous operations, returning promises for all network calls. As of its last major release, version 0.2.5 (published in 2016), it supports in-memory, Redis, and MongoDB caching via pluggable transporters. The package was primarily built for Node.js environments around `~0.10.x`, making it incompatible with modern Node.js runtimes. Its key differentiators at the time were its promise-based API (using Q) and an extensible caching mechanism. The project appears to be abandoned, with no significant updates or maintenance for nearly a decade.
Common errors
-
Error: Cannot find module 'requestify'
cause The package `requestify` is not installed or the `require()` path is incorrect.fixEnsure `requestify` is listed in your `package.json` dependencies and installed via `npm install` or `yarn install`. Verify the `require('requestify')` statement is correct. -
TypeError: requestify.get is not a function
cause The `requestify` module was not successfully loaded or the object is not the expected Requestify instance. This can happen with incorrect `require()` usage or if a different module is aliased as `requestify`.fixConfirm `const requestify = require('requestify');` executed without error. Check for any naming conflicts in your scope that might be overwriting the `requestify` variable. -
UnhandledPromiseRejectionWarning: DeprecationWarning: A promise was rejected with a non-error: [object Object]
cause This warning, often seen in older Node.js versions or with specific promise libraries like Q, indicates that a promise rejected with a value that is not an `Error` object, or that a promise rejection was not caught.fixAlways reject promises with `new Error('message')` instead of plain strings or objects. Ensure all promises have a `.fail()` or `.then(null, onRejected)` handler to catch rejections. Upgrade Node.js if possible, as this warning might be indicative of other compatibility issues. -
ReferenceError: Promise is not defined
cause This error occurs in very old Node.js environments where native ES6 `Promise` is not globally available, or if transpilation targets an environment without `Promise`.fixWhile `requestify` uses `Q` promises (which does not depend on native `Promise`), attempting to use native `Promise` methods without a polyfill in old Node.js (~0.10.x) would cause this. Ensure you are exclusively using `Q`'s promise API or explicitly polyfill `Promise` if mixing.
Warnings
- breaking Requestify requires Node.js version ~0.10.x. It is largely incompatible with modern Node.js versions (v12+). Running it on newer Node.js runtimes will likely result in unexpected behavior or errors due to API changes and removed core modules.
- gotcha Requestify uses the 'Q' promise library for asynchronous operations, not native ES6 Promises. Developers expecting native Promise behavior (e.g., `catch()` instead of `fail()`, `finally()`) or interoperability might encounter issues.
- deprecated The `requestify.redis(redisInstance)` method is deprecated. Users should instead configure the Redis cache transporter directly via `requestify.cacheTransporter(requestify.coreCacheTransporters.redis(myRedisInstance));`.
- gotcha The Requestify project appears to be abandoned. Its last publish date was 9 years ago (2016), and it targets a very old Node.js engine (~0.10.x). This means it receives no security updates, bug fixes, or new features.
- gotcha Requestify lacks native TypeScript support and modern JavaScript features (e.g., `async/await` syntax, `fetch` API alternatives). This can lead to less ergonomic code and challenges in TypeScript-first projects.
Install
-
npm install requestify -
yarn add requestify -
pnpm add requestify
Imports
- requestify
import requestify from 'requestify';
const requestify = require('requestify'); - requestify.get
requestify().get('http://example.com');requestify.get('http://example.com').then(...); - requestify.coreCacheTransporters
import { coreCacheTransporters } from 'requestify';const coreCacheTransporters = requestify.coreCacheTransporters;
Quickstart
const requestify = require('requestify');
async function performRequests() {
// Set a custom encoding (optional, utf8 is default)
requestify.setEncoding('utf8');
// Example GET request
console.log('Performing GET request...');
try {
const getResponse = await requestify.get('https://httpbin.org/get').then(function(response) {
return response.getBody(); // Q-promise .then()
});
console.log('GET Response Body:', getResponse);
} catch (error) {
console.error('GET Error:', error.message || error.code || error);
}
// Example POST request with JSON body
console.log('\nPerforming POST request...');
try {
const postResponse = await requestify.post('https://httpbin.org/post', {
hello: 'world',
timestamp: new Date().toISOString()
}).then(function(response) {
return response.getBody(); // Q-promise .then()
});
console.log('POST Response Body:', postResponse);
} catch (error) {
console.error('POST Error:', error.message || error.code || error);
}
// Example GET request with caching enabled (requires cache transporter setup)
console.log('\nPerforming cached GET request...');
// Using the default in-memory cache transporter
const coreCacheTransporters = requestify.coreCacheTransporters;
requestify.cacheTransporter(coreCacheTransporters.inMemory());
try {
const cachedGetResponse = await requestify.get('https://httpbin.org/delay/1', {
cache: { cache: true, expires: 5000 } // Cache for 5 seconds
}).then(function(response) {
return response.getBody();
});
console.log('Cached GET Response Body (first call):', cachedGetResponse);
// Immediately fetch again, should be from cache if within 5 seconds
const cachedGetResponse2 = await requestify.get('https://httpbin.org/delay/1', {
cache: { cache: true, expires: 5000 }
}).then(function(response) {
return response.getBody();
});
console.log('Cached GET Response Body (second call, should be fast):', cachedGetResponse2);
} catch (error) {
console.error('Cached GET Error:', error.message || error.code || error);
}
}
performRequests();