A tiny Node.js module for retrieving a request's Details (ip,os,browser)

Overview

request-details

A tiny Node.js module for retrieving a request's Details (ip,os,browser)

⌨️ Installation

npm install request-details

⚙️ Usage

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

app.use(RequestDetails.middleware) // it will add the details to the request object, (Optional)

// when you not use middleware:
app.get('/',  (req, res) => {
  const details = new RequestDetails(req);
  console.log(details.getDevice())
});

📦 Methods

🔓 Public Methods

🔒 Private Methods

📍 Static Methods

Examples

JavaScript Javascript

const express = require('express');
const app = express();

const request_Detail = requir('request-details').default


app.set("trust proxy", true);


app.get('/', async (req, res, next) => {
    const requestD = new request_Detail(req)
    const ipDetails = await requestD.getIpInfo()
    res.json(ipDetails)
})

// With Middleware
app.use(request_Detail.middleware)
app.get('/ip', async (req, res, next) => {
    const ipDetails = await req.info.getIpInfo()
    res.json(ipDetails)
})

app.get('/os', (req, res, next) => {
    const osDetails = req.info.getOs()
    res.json(osDetails)
})

app.get('/browser', (req, res, next) => {
    const BrDetails = req.info.getBrowser()
    res.json(BrDetails)
})
//end Middleware
app.listen(3000)


TypeScript TypeScript

import RequestDetail from 'request-details'
import express, { Request, Response } from 'express'


const app = express()

app.use(RequestDetail.middleware)
app.get('/', async (req: Request, res: Response) => {
    try {
        const ipDet = await req.info.getIpInfo()
        res.json(ipDet)
    } catch (error: any) {
        res.status(500).send(error.message)
    }
})


app.get("/ipD", async (req: Request, res: Response) => {
    try {
        const targetIp = req.query.ip
        const ip = await RequestDetail.getIpInfoByIp(String(targetIp))
        res.json(ip)
    } catch (error: any) {
        res.status(500).send(error.message)
    }
})

// Without Middleware
app.get('/full', (req: Request, res: Response) => {

    const requestDetail = new RequestDetail(req)
    const browser = requestDetail.getBrowser()
    const os = requestDetail.getOs()

    res.json({
        browser,
        os
    })
})


app.listen(3000)

getIpInfo (Promise)

{
    "ip": string,
    "country": string,
    "country_code": string,
    "city": string,
    "continent":string,
    "latitude": double,
    "longitude": double,
    "time_zone": string,
    "postal_code": string,
    "org": string,
    "asn": string,
    "subdivision": string,
    "subdivision2": string
}

getOs

{
 "name": string,
 "version": string 
}

getBrowser

{
    "name": string,
    "version": string
}

getDevice

{
    /**
         * Determined dynamically
         */
        "model": string | undefined;

        /**
         * Possible type:
         * console, mobile, tablet, smarttv, wearable, embedded
         */
        "type": string | undefined;

        /**
         * Possible vendor:
         * Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
         * Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
         * Nintendo, Nokia, Nvidia, Ouya, Palm, Panasonic, Polytron, RIM, Samsung, Sharp,
         * Siemens, Sony-Ericsson, Sprint, Xbox, ZTE
         */
        "vendor": string | undefined;
}

getCPU

{
   "architecture": string | undefined;
}

fetchUserAgent

fetchUserAgent(req.headers['user-agent'])
// output:
 /// This will print an object structured like this:
       /* {
            ua: "",
            browser: {
                name: "",
                version: "",
                major: "" //@deprecated
            },
            engine: {
                name: "",
                version: ""
            },
            os: {
                name: "",
                version: ""
            },
            device: {
                model: "",
                type: "",
                vendor: ""
            },
            cpu: {
                architecture: ""
            }
        }
    */

getIpInfoByIp (Promise)

getIpInfoByIp("ip")
// output:
/*{
  
    "ip": string,
    "country": string,
    "country_code": string,
    "city": string,
    "continent":string,
    "latitude": double,
    "longitude": double,
    "time_zone": string,
    "postal_code": string,
    "org": string,
    "asn": string,
    "subdivision": string,
    "subdivision2": string
 
}*/

middleware

app.use(RequestDetail.middleware)
You might also like...

Isomorphic WHATWG Fetch API, for Node & Browserify

isomorphic-fetch Fetch for node and Browserify. Built on top of GitHub's WHATWG Fetch polyfill. Warnings This adds fetch as a global so that its API i

Jan 2, 2023

SPDY server on Node.js

SPDY Server for node.js With this module you can create HTTP2 / SPDY servers in node.js with natural http module interface and fallback to regular htt

Jan 4, 2023

libcurl bindings for Node.js

node-libcurl The fastest URL transfer library for Node.js. libcurl bindings for Node.js. libcurl official description: libcurl is a free and easy-to-u

Jan 2, 2023

Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js

rocky A multipurpose, full-featured, middleware-oriented and hackable HTTP/S and WebSocket proxy with powerful built-in features such as versatile rou

Nov 24, 2022

Simplifies node HTTP request making.

Requestify - Simplifies node HTTP request making. Requestify is a super easy to use and extendable HTTP client for nodeJS + it supports cache (-:. Ins

Nov 28, 2022

A fully-featured Node.js REST client built for ease-of-use and resilience

A fully-featured Node.js REST client built for ease-of-use and resilience

flashheart A fully-featured Node.js REST client built for ease-of-use and resilience flashheart is built on http-transport to provide everything you n

Jun 21, 2022

Run HTTP over UDP with Node.js

nodejs-httpp - Run HTTP over UDP based transport and Bring Web in Peer or P2P styles main js modules: udt.js, httpp.js, udts.js and httpps.js, that's

Aug 2, 2022

一个基于node.js,express,socket.io的websocket非常棒的聊天室,代码简单很适合新手. A very nice websocket chat room based on node.js, express, socket.io. the code is simple, very suitable for novices

一个基于node.js,express,socket.io的websocket非常棒的聊天室,代码简单很适合新手.  A very nice websocket chat room based on node.js, express, socket.io. the code is simple, very suitable for novices

来来往下看,虽然教程又臭又长但是一步步地保姆式教学很简单的,毕竟我是真菜鸟嘛,当然什么都往细了说╮(╯_╰)╭ 一、使用方法 该教程内容所有指令都为Linux CentOS 7.x环境下指令,其他平台请您自行查询(⊙x⊙;) 1.下载node.js并下载Sakura_Chat_Room node.j

Jul 21, 2022

node

node

第一步 安装 node node版本须大于14 安装地址http://nodejs.cn/安装页面上的版本即可 下载对应你的系统的安装包 打开安装包,一直下一步到安装完成即可 填入你的cookie inTimeActive 和 longActive 里面的jdCookie.js填入你的cookie

Feb 17, 2022
Releases(Latest)
Owner
sajjad MrX
javascript for ever !
sajjad MrX
Wrap native HTTP requests with RFC compliant cache support

cacheable-request Wrap native HTTP requests with RFC compliant cache support RFC 7234 compliant HTTP caching for native Node.js HTTP/HTTPS requests. C

Luke Childs 259 Dec 20, 2022
Library agnostic in-process recording of http(s) requests and responses

@gr2m/http-recorder Library agnostic in-process recording of http(s) requests and responses Install npm install @gr2m/http-recorder Usage import http

Gregor Martynus 4 May 12, 2022
A light-weight module that brings the Fetch API to Node.js

A light-weight module that brings Fetch API to Node.js. Consider supporting us on our Open Collective: Motivation Features Difference from client-side

Node Fetch 8.1k Jan 4, 2023
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API 中文 | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

null 17 Dec 12, 2022
Run Node.js on Android by rewrite Node.js in Java

node-android Run Node.js on Android by rewrite Node.js in Java with the compatible API. third-party: libuvpp, libuv-java JNI code by Oracle. Build Clo

AppNet.Link 614 Nov 15, 2022
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
A full-featured http proxy for node.js

node-http-proxy node-http-proxy is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as

http ... PARTY! 13.1k Jan 3, 2023
HTTP server mocking and expectations library for Node.js

Nock HTTP server mocking and expectations library for Node.js Nock can be used to test modules that perform HTTP requests in isolation. For instance,

Nock 11.9k Jan 3, 2023
🌐 Human-friendly and powerful HTTP request library for Node.js

Sindre's open source work is supported by the community. Special thanks to: Human-friendly and powerful HTTP request library for Node.js Moving from R

Sindre Sorhus 12.5k Jan 9, 2023