Negotiator is a lightweight, standalone utility for parsing and evaluating HTTP `Accept`, `Accept-Language`, `Accept-Encoding`, and `Accept-Charset` headers. It allows servers to determine the client's preferred content based on quality values (`q-factors`) specified in these headers. Primarily maintained by the `jshttp` organization, it serves as a core component for web frameworks like Express.js by abstracting complex RFC specifications for content negotiation. The current stable version is `1.0.0`. The package operates in a maintenance mode, with infrequent but significant major releases that often include breaking changes to align with evolving Node.js environments and best practices. It distinguishes itself by providing a robust and dependency-free solution for this specific HTTP concern.
npm install negotiatorVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing Negotiator with mock request headers and using its methods to determine preferred content types, languages, and encodings based on client preferences and available options.
Upgrade Node.js to version 18 or higher, or pin `negotiator` to `^0.6.0` in your `package.json`.
Thoroughly test negotiation logic with various `Accept` header values and explicit `q` factors. Refer to RFC 7231 for details on `q` values.
Upgrade to `negotiator@0.5.3` or newer to benefit from internal fixes for case-insensitive parameter matching. Always test your header parsing logic.
Always include `identity` in your `availableEncodings` list if you intend to support uncompressed responses, and be aware of its default `q` value if not specified otherwise.
For ESM, use `import Negotiator from 'negotiator';`. For CommonJS, use `const Negotiator = require('negotiator');` and then `new Negotiator(request);`.Inspect the raw `Accept` headers received by the server. Verify the `q` values and syntax. Ensure the `available` array passed to `negotiator.mediaType(available)` accurately reflects what your application can provide and is not empty.
No dependency data recorded yet.