{"id":18595,"library":"negotiate","title":"Negotiate.js","description":"JavaScript implementation of the HTTP preemptive content negotiation algorithm as defined in the original HTTP 1.1 draft spec. Stable version 1.0.1, no longer actively developed. Differentiators: implements the original draft negotiation algorithm (not the final RFC), handles media type, language, charset, and encoding negotiation. Suitable for Node.js HTTP servers needing automatic variant selection. Alternative to content-negotiation libraries that follow the final RFC.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git@github.com:RubenVerborgh/negotiate-js","tags":["javascript","http","content","negotiation","variants","node","accept"],"install":[{"cmd":"npm install negotiate","lang":"bash","label":"npm"},{"cmd":"yarn add negotiate","lang":"bash","label":"yarn"},{"cmd":"pnpm add negotiate","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import; CommonJS require works but is not the recommended pattern","wrong":"const Negotiate = require('negotiate')","symbol":"Negotiate","correct":"import Negotiate from 'negotiate'"},{"note":"Named export for the choose function; prefer named import for clarity.","wrong":"const { choose } = require('negotiate')","symbol":"choose","correct":"import { choose } from 'negotiate'"},{"note":"CommonJS require gets the default export; named import with braces will not work.","wrong":"import { Negotiate } from 'negotiate'","symbol":"Negotiate","correct":"const Negotiate = require('negotiate')"}],"quickstart":{"code":"import Negotiate from 'negotiate';\n\nconst variants = [\n  {\n    method: 'GET',\n    type: 'text/html',\n    language: 'en-ca',\n    charset: 'iso-8859-1',\n    encoding: null,\n    quality: 1.0,\n    length: 36741,\n    filename: 'blog.html'\n  },\n  {\n    method: 'GET',\n    type: 'application/atom+xml',\n    language: 'en',\n    charset: 'utf-8',\n    encoding: 'gzip',\n    quality: 0.8,\n    length: 12987,\n    filename: 'blog.atom.gzip'\n  }\n];\n\nconst request = {\n  url: '/blog',\n  method: 'GET',\n  headers: {\n    'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',\n    'accept-language': 'en-US,en;q=0.8',\n    'accept-encoding': 'gzip,deflate,sdch',\n    'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'\n  }\n};\n\nconst responses = Negotiate.choose(variants, request);\nconsole.log(responses[0]);","lang":"typescript","description":"Shows how to define variants and select the best representation for an HTTP request using negotiate.choose()."},"warnings":[{"fix":"Ensure your expected negotiation behavior matches the draft algorithm; test with various Accept headers.","message":"The algorithm implements the original HTTP 1.1 draft spec, not the final RFC 7231. Results may differ from other content negotiation libraries.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using an actively maintained alternative like 'content-negotiator' or implement RFC 7231 negotiation yourself.","message":"The package has not been updated since 2015 and depends on older Node.js patterns. No security patches have been applied.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always explicitly set the quality property on each variant to control priority.","message":"Variant quality factor defaults to 1.0 if not specified, which may cause unexpected selections if you omit quality values.","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":"Add const Negotiate = require('negotiate'); or import Negotiate from 'negotiate'; at the top of your file.","cause":"Using the library without importing it first.","error":"Negotiate is not defined"},{"fix":"Run npm install negotiate --save to install the package.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'negotiate'"},{"fix":"Wrap your variant in an array: Negotiate.choose([variant], request);","cause":"Passing a single object instead of an array of variants.","error":"TypeError: variants is not iterable"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}