Socket
Socket
Sign inDemoInstall

express-ua-middleware

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-ua-middleware

Express middleware to parse user-agent header


Version published
Weekly downloads
7
decreased by-22.22%
Maintainers
1
Install size
111 kB
Created
Weekly downloads
 

Readme

Source

Express user-agent Middleware

Express middleware to parse user-agent header

Install

npm i express-ua-middleware

#or

yarn add express-ua-middleware

Use

This is a middleware to provide parsed user agent header, to use simply, import module, then use it on express.use method.

const userAgent = require("express-ua-middleware");
const express = require("express");
const server = express();

server.use(userAgent);

server.get("/", (req, res) => {
	console.log(req.userAgent);
	/**
	 * Example
	 * {
	 *	 raw: "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Mobile Safari/537.36",
	 *	 browser: {
	 *	 	name: "Chrome",
	 *	 	version: "77"
	 *	 },
	 *	 os: {
	 *	 	name: "Android",
	 *	 	version: "5.0"
	 *	 },
	 *	 device: {
	 *	 	vendor: "Samsung",
	 *	 	model: "SM-G900P"
	 *	 }
	 * }
	 */
})

Or you can use as parser, with method userAgentFromString

server.get("/", (req, res) => {
	console.log(req.userAgentFromString(req.headers["user-agent"]));
	/**
	 * Example
	 * {
	 *	 browser: {
	 *	 	name: "Chrome",
	 *	 	version: "77"
	 *	 },
	 *	 os: {
	 *	 	name: "Android",
	 *	 	version: "5.0"
	 *	 },
	 *	 device: {
	 *	 	vendor: "Samsung",
	 *	 	model: "SM-G900P"
	 *	 }
	 * }
	 */
})

Contributing

To contribute with the project, open a issue on Github or create a Pull Request

Keywords

FAQs

Last updated on 08 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc