universal-user-agent is a JavaScript library designed to retrieve a user agent string consistently across various runtime environments, including browsers and Node.js. It is currently stable at version 7.0.3 and maintains an irregular release cadence, primarily driven by bug fixes and necessary environment compatibility updates. Its key differentiator is its ability to abstract away environment-specific logic, providing a unified `getUserAgent` function. This makes it particularly useful for libraries and applications that need to report consistent user agent information regardless of where they are executed, for purposes such as API logging, telemetry, or feature detection.
npm install universal-user-agentVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use `getUserAgent` to log the detected user agent string and infer the runtime environment (browser or Node.js).
Migrate your project to use ES Modules, or use dynamic `import()` if you must use it within a CommonJS module. For example: `const { getUserAgent } = await import('universal-user-agent');`Ensure your Node.js runtime is version 12 or newer. Update your development and production environments accordingly.
Update any parsing logic or regular expressions that relied on the detailed OS name and version previously included in the Node.js user agent string.
Review any error handling logic that expected `getUserAgent()` to throw. Instead, check for the specific fallback string `<environment undetectable>` if you need to identify scenarios where the user agent could not be determined.
If using CommonJS (before v7's ESM-only change), update your imports from `const getUserAgent = require("universal-user-agent")` to `const { getUserAgent } = require("universal-user-agent")`.For CommonJS (pre-v7), use `const { getUserAgent } = require('universal-user-agent');`. For ESM (v7+), use `import { getUserAgent } from 'universal-user-agent';`.This package is pure ESM since v7.0.0. Convert your project to use ES Modules or use dynamic `import()` within your CommonJS module (e.g., `const { getUserAgent } = await import('universal-user-agent');`).Ensure your code handles different environments gracefully. The `universal-user-agent` library itself is designed to work in both, but if your application logic directly uses Node-specific globals, guard them with checks like `if (typeof process !== 'undefined') { /* Node.js specific code */ }`.No dependency data recorded yet.