npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

request-details

v1.0.6

Published

show request details

Downloads

33

Readme

request-details

a Node.js package that provides a class for handling request details in an Express application. It extracts information related to the user's IP, operating system (OS), browser, device, and CPU from the user agent string in the HTTP request headers.

⌨️ Installation

npm install request-details

⚙️ Usage

To use Request-Details in your Express application, you can import the RequestDetail class from the package and create an instance of it with the Express request object. Here's an example:

const RequestDetails = require('request-details').default;
// CommonJS:
import RequestDetails from 'request-details';

import express from "express";

const app = express();

app.get("/", (req, res) => {
  const requestDetail = new RequestDetail(req);
  // Get IP info
  requestDetail.getIpInfo()
    .then(ipInfo => {
      console.log(ipInfo);
      // { ip: '127.0.0.1', country: 'US', city: 'New York', ... }
    })
    .catch(err => {
      console.error(err);
    });

  // Get OS info
  const os = requestDetail.getOs();
  console.log(os); // { name: 'Windows', version: '10' }

  // Get browser info
  const browser = requestDetail.getBrowser();
  console.log(browser); // { name: 'Chrome', version: '58.0.3029.110' }

  // Get device info
  const device = requestDetail.getDevice();
  console.log(device); // { type: 'desktop', vendor: 'Unknown', model: 'Unknown' }

  // Get CPU info
  const cpu = requestDetail.getCPU();
  console.log(cpu); // { architecture: 'amd64' }

  res.send("Hello world!");
});

app.use(RequestDetails.middleware); // It will add the details to the request object (optional)
app.get('/middleware', async (req, res, next) => {
    const ipDetails = await req.info.getIpInfo()
    res.json(ipDetails)
})

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});

💡 Features

  • Retrieve IP address, operating system, and browser information from incoming HTTP requests.
  • Optional middleware to automatically add request details to the request object.
  • Simple and easy-to-use API with intuitive methods for retrieving request details.
  • Works with Express, NestJs, and other Node.js web frameworks.
  • Supports CommonJS and ES modules for importing in your project.

🚀 API

RequestDetail

  • constructor(req: Request, options?: Options): Creates an instance of the RequestDetail class with the Express request object and optional options to configure the instance.
  • getIpInfo(): Promise<I_iplocate>: Get information related to user's IP. Returns a Promise that resolves with the IP information.
  • setOptions(options: Options): void: Sets the options for the RequestDetail instance.
  • getOs(): OS | null: Get the operating system (OS) information from the user agent.
  • getBrowser(): Browser | null: Get the browser information from the user agent.
  • getDevice(): Device | null: Get the device information from the user agent.
  • getCPU(): CPU | null: Get the CPU information from the user agent.
  • static fetchUserAgent(userAgent: string): Get user agent from a user agent string.
  • static getIpInfoByIp(ip: string, token?: string): Promise<I_iplocate>: Get IP information for a specific IP address.

🤝 Contributing

If you would like to contribute to Request-Details, please open an issue or submit a pull request on the GitHub repository. 🔧💻🔍