Registry / http-networking / negotiate

negotiate

JSON →
library0.0.1jsnpmunverified

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.

npm install negotiate
INSTALL
IMPORT
SIG · NEGOTIATE
N
negotiate
http-networkingjavascriptv0.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Negotiate
import Negotiate from 'negotiate'
const Negotiate = require('negotiate')
ESM default import; CommonJS require works but is not the recommended pattern
choose
import { choose } from 'negotiate'
const { choose } = require('negotiate')
Named export for the choose function; prefer named import for clarity.
Negotiate
const Negotiate = require('negotiate')
import { Negotiate } from 'negotiate'
CommonJS require gets the default export; named import with braces will not work.

Shows how to define variants and select the best representation for an HTTP request using negotiate.choose().

import Negotiate from 'negotiate'; const variants = [ { method: 'GET', type: 'text/html', language: 'en-ca', charset: 'iso-8859-1', encoding: null, quality: 1.0, length: 36741, filename: 'blog.html' }, { method: 'GET', type: 'application/atom+xml', language: 'en', charset: 'utf-8', encoding: 'gzip', quality: 0.8, length: 12987, filename: 'blog.atom.gzip' } ]; const request = { url: '/blog', method: 'GET', headers: { 'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'accept-language': 'en-US,en;q=0.8', 'accept-encoding': 'gzip,deflate,sdch', 'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3' } }; const responses = Negotiate.choose(variants, request); console.log(responses[0]);
Debug
Known issues
gotchaThe algorithm implements the original HTTP 1.1 draft spec, not the final RFC 7231. Results may differ from other content negotiation libraries.
fix
Ensure your expected negotiation behavior matches the draft algorithm; test with various Accept headers.
affects: >=1.0.0
gotchaThe package has not been updated since 2015 and depends on older Node.js patterns. No security patches have been applied.
fix
Consider using an actively maintained alternative like 'content-negotiator' or implement RFC 7231 negotiation yourself.
affects: >=1.0.0
gotchaVariant quality factor defaults to 1.0 if not specified, which may cause unexpected selections if you omit quality values.
fix
Always explicitly set the quality property on each variant to control priority.
affects: >=1.0.0
Errors
Common errors & fixes
Negotiate is not defined
Using the library without importing it first.
fix
Add const Negotiate = require('negotiate'); or import Negotiate from 'negotiate'; at the top of your file.
Cannot find module 'negotiate'
Package not installed or missing from node_modules.
fix
Run npm install negotiate --save to install the package.
TypeError: variants is not iterable
Passing a single object instead of an array of variants.
fix
Wrap your variant in an array: Negotiate.choose([variant], request);
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
negotiate — npm install negotiate · libregistry