{"id":17142,"library":"ajax-request","title":"Simplified HTTP Request for Node.js","description":"ajax-request is a basic, callback-based HTTP client library designed for Node.js, offering functionalities for sending GET and POST requests, as well as direct file downloads. Currently at version 1.2.3, this package appears to have an inactive or ceased release cadence, with its last update occurring approximately 8 years ago. Key differentiators include its straightforward API for common HTTP operations and built-in file downloading, which was more unique at the time of its active development. However, it significantly lags behind modern HTTP clients, lacking support for Promises/async-await and ES Modules, and does not ship with TypeScript definitions. The `base64` utility method has been deprecated and migrated to a separate package, signaling a lack of ongoing maintenance for this core library.","status":"abandoned","version":"1.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/douzi8/ajax-request","tags":["javascript","request","http","ajax","http download","image","json"],"install":[{"cmd":"npm install ajax-request","lang":"bash","label":"npm"},{"cmd":"yarn add ajax-request","lang":"bash","label":"yarn"},{"cmd":"pnpm add ajax-request","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not support ES module `import` syntax. Attempting to use `import` will result in a runtime error.","wrong":"import request from 'ajax-request';","symbol":"request","correct":"const request = require('ajax-request');"},{"note":"The `post` method is available as a property of the default `request` export in CommonJS. It is not a named export for ES Modules.","wrong":"import { post } from 'ajax-request';","symbol":"request.post","correct":"const request = require('ajax-request');\nrequest.post(options, callback);"},{"note":"The `download` method is available as a property of the default `request` export in CommonJS. It is not a named export for ES Modules.","wrong":"import { download } from 'ajax-request';","symbol":"request.download","correct":"const request = require('ajax-request');\nrequest.download(options, callback);"}],"quickstart":{"code":"const request = require('ajax-request');\n\n// Example 1: Basic GET request\nrequest('https://jsonplaceholder.typicode.com/posts/1', function(err, res, body) {\n  if (err) {\n    console.error('GET Error:', err);\n    return;\n  }\n  console.log('GET Response (Status Code):', res.statusCode);\n  console.log('GET Response (Body):', JSON.parse(body));\n});\n\n// Example 2: POST request with data\nrequest({\n  url: 'https://jsonplaceholder.typicode.com/posts',\n  method: 'POST',\n  data: {\n    title: 'foo',\n    body: 'bar',\n    userId: 1\n  },\n  json: true // Automatically parse response body as JSON\n}, function(err, res, body) {\n  if (err) {\n    console.error('POST Error:', err);\n    return;\n  }\n  console.log('POST Response (Status Code):', res.statusCode);\n  console.log('POST Response (Body):', body);\n});\n\n// Example 3: Download a file (replace with a real, small file URL for testing)\n// NOTE: This will attempt to save a file to the current working directory.\nconst fs = require('fs');\nconst tempFilePath = './downloaded-image.png';\n\nrequest.download({\n  url: 'https://via.placeholder.com/150/FF0000/FFFFFF?text=Test',\n  destPath: tempFilePath\n}, function(err, res, body, destpath) {\n  if (err) {\n    console.error('Download Error:', err);\n    return;\n  }\n  console.log(`File downloaded to: ${destpath}`);\n  // Verify file existence (optional)\n  if (fs.existsSync(tempFilePath)) {\n    console.log('Downloaded file exists!');\n    fs.unlinkSync(tempFilePath); // Clean up\n  }\n});","lang":"javascript","description":"This quickstart demonstrates how to perform a simple GET request, a POST request with JSON data, and download a file using the callback-based API of `ajax-request`."},"warnings":[{"fix":"Consider migrating to a modern HTTP client library for Node.js such as `axios`, `node-fetch`, or the built-in `fetch` API (available in Node.js >= 18) for better security, features, and maintainability.","message":"The `ajax-request` package is significantly outdated (v1.2.3, last published ~8 years ago) and appears to be unmaintained. It lacks modern features like Promise-based APIs or `async/await` support, relying solely on callbacks.","severity":"gotcha","affected_versions":"<=1.2.3"},{"fix":"Ensure your project uses `require()` for importing `ajax-request`. For new projects, consider using a modern library that supports ES Modules or the native Node.js `fetch` API.","message":"The package is CommonJS-only and does not support ES Modules. Attempting to use `import` syntax will result in a runtime `ERR_REQUIRE_ESM` error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For base64 image functionality, refer to the `base64-img` package or implement the conversion manually using Node.js's built-in `Buffer` and file system modules.","message":"The `request.base64` method has been explicitly deprecated and moved to a separate package. Its functionality is no longer part of `ajax-request`.","severity":"deprecated","affected_versions":">=1.2.0"},{"fix":"Migrate to a actively maintained HTTP client. If immediate migration is not possible, for testing or specific controlled environments, Node.js can be run with `NODE_TLS_REJECT_UNAUTHORIZED='0'` (NOT recommended for production) or a custom agent with `rejectUnauthorized: false` for `http.request` based calls, but this is a significant security risk.","message":"Due to its age, `ajax-request` might not correctly handle modern TLS/SSL certificates, leading to `UNABLE_TO_VERIFY_LEAF_SIGNATURE` or similar errors when connecting to contemporary HTTPS endpoints. It also lacks explicit security updates for potential vulnerabilities.","severity":"gotcha","affected_versions":"<=1.2.3"},{"fix":"Manually create declaration files (e.g., `ajax-request.d.ts`) or use a modern HTTP client that provides official TypeScript support.","message":"The package does not ship with TypeScript type definitions, leading to poor developer experience and lack of type safety in TypeScript projects.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change `import request from 'ajax-request';` to `const request = require('ajax-request');` and ensure your project is configured for CommonJS or uses dynamic `import()` if mixed modules are necessary.","cause":"Attempting to `import` the `ajax-request` package in an ES Module context.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module [path] not supported"},{"fix":"Ensure that a function is passed as the `callback` argument to `request()`, `request.post()`, or `request.download()` methods.","cause":"The request method (or its variants) was called without providing a callback function as the last argument.","error":"TypeError: callback is not a function"},{"fix":"Update Node.js to a recent version. If the server uses a self-signed certificate in a controlled environment, you might temporarily set `NODE_TLS_REJECT_UNAUTHORIZED='0'` (NOT for production) or add the certificate to your trusted store. The best fix is to migrate to a modern, maintained HTTP client library.","cause":"The Node.js environment failed to verify the SSL certificate of the target server, often due to an outdated root certificate store or a self-signed certificate.","error":"Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE"}],"ecosystem":"npm","meta_description":null}