{"id":18230,"library":"cogent","title":"cogent","description":"Cogent is a simple HTTP request library built for Node.js and generators using co. It supports redirect resolution, timeout, automatic gunzip decompression, and first-class JSON parsing. The response can be buffered, saved to a file, or returned as parsed JSON. Options include retries, timeouts, and customizable request properties. Version 1.0.1 is stable but the package is part of the cojs ecosystem and has seen no recent updates. It relies on generators and the co library, making it less suitable for modern async/await workflows without additional wrapping.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/cojs/cogent","tags":["javascript"],"install":[{"cmd":"npm install cogent","lang":"bash","label":"npm"},{"cmd":"yarn add cogent","lang":"bash","label":"yarn"},{"cmd":"pnpm add cogent","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for generator-based async control flow; cogent itself returns a generator function.","package":"co","optional":false}],"imports":[{"note":"Default import; the module exports a generator function directly.","symbol":"request","correct":"import request from 'cogent'"},{"note":"CommonJS requires the default export, not a named property.","wrong":"const { request } = require('cogent')","symbol":"request","correct":"const request = require('cogent')"},{"note":"Named export for creating a new instance with default options.","wrong":"import extend from 'cogent/extend'","symbol":"extend","correct":"import { extend } from 'cogent'"}],"quickstart":{"code":"const co = require('co');\nconst request = require('cogent');\n\nco(function* () {\n  const res = yield* request('https://api.github.com/repos/visionmedia/express/package.json', { json: true });\n  console.log(res.body);\n}).catch(err => console.error(err));","lang":"javascript","description":"Demonstrates fetching a JSON endpoint using a generator function, parsing JSON response, and logging the body."},"warnings":[{"fix":"Use async/await with a library that returns promises (e.g., node-fetch).","message":"Generator-based APIs are outdated; prefer async/await with modern HTTP libraries like node-fetch or axios.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Wrap with co: const wrapped = co(require('cogent'));","message":"When using 'cogent' without co, the generator must be yielded manually.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check res.statusCode before accessing res.body.","message":"The 'json' option only populates res.body on a 200 status code; non-200 responses will not have a parsed body.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use yield* request(uri) inside a generator, or wrap with co.","cause":"Attempting to call the generator without using yield* or co.","error":"TypeError: request(...) is not a function"},{"fix":"Ensure the containing function is a generator (function*).","cause":"Using yield outside of a generator function.","error":"ReferenceError: yield is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}