User-agent information plugin for Fastify.
npm install fastify-user-agent
| Plugin version | Fastify version |
|---|---|
^2.0.0 |
^5.0.0 |
^1.0.0 |
^4.0.0 |
The plugin adds a userAgent property to the request object by parsing the user-agent header.
The object is an agent instance and it has the following properties:
familyThe browser family, or browser name, it defaults to Other.majorThe major version number of the family, it defaults to 0.minorThe minor version number of the family, it defaults to 0.patchThe patch version number of the family, it defaults to 0.osOperatingSystem instancedeviceDevice instance
const fastify = require('fastify')
const app = fastify()
app.register(require('fastify-user-agent'))
app.get('/', async (request, reply) => {
return request.userAgent
})
app.listen({ port: 3000 })You can pass the following options during the registration:
| Option | Default | Description |
|---|---|---|
name |
userAgent |
Change the request property name where the plugin will store the parsed user-agent information. |
Licensed under MIT.