RequestDetail

Represents a class for handling request details in an Express application.

Constructor

new RequestDetail(req, options)

Creates an instance of the RequestDetails class.

Parameters:
NameTypeDescription
reqRequest

The Express request object.

optionsOptions

The options to configure the RequestDetails instance.

Members

(static) fetchUserAgent

Get user agent.

Example
fetchUserAgent(req.headers['user-agent'])

Methods

getBrowser() → {Browser|null}

Get the browser information from the user agent

Returns:
  • An object representing the browser information, or null if not available
Type: 
Browser | null
Example
const browser = requestDetail.getBrowser();
console.log(browser); // { name: 'Chrome', version: '58.0.3029.110' }

getCPU() → {CPU|null}

Get the CPU information from the user agent

Returns:
  • An object representing the CPU information, or null if not available
Type: 
CPU | null
Example
const cpu = requestDetail.getCPU();
console.log(cpu); // { architecture: 'amd64' }

getDevice() → {Device|null}

Get the device information from the user agent

Returns:
  • An object representing the device information, or null if not available
Type: 
Device | null
Example
const device = requestDetail.getDevice();
console.log(device); // { type: 'desktop', vendor: 'Unknown', model: 'Unknown' }

getIpInfo() → {Promise.<I_iplocate>}

Get information related to user's IP

Returns:
  • A Promise that returns the information related to user's IP upon success
Type: 
Promise.<I_iplocate>
Example
const ipInfo = await requestDetail.getIpInfo();
console.log(ipInfo); // { ip: '127.0.0.1', country: 'US', city: 'New York', ... }

getOs() → {OS|null}

Get the operating system (OS) information from the user agent.

Returns:
  • An object representing the OS information, or null if not available.
Type: 
OS | null
Example
const os = requestDetail.getOs();
console.log(os); // { name: 'Windows', version: '10' }

setOptions(options) → {void}

Sets the options for the RequestDetails instance.

Parameters:
NameTypeDescription
optionsOptions

The options to set.

Returns:
Type: 
void

(static) getIpInfoByIp(ip, token) → {Promise.<I_iplocate>}

Get IP information for a specific IP address

Parameters:
NameTypeDescription
ipstring

The IP address

tokenstring | undefined

The iplocate token

Returns:
  • A Promise that returns the information related to the specific IP address upon success
Type: 
Promise.<I_iplocate>
Example
const ipInfo = await RequestDetail.getIpInfo('192.168.0.1');
console.log(ipInfo); // { ip: '192.168.0.1', country: 'US', city: 'New York', ... }

(static) middleware(req, res, next)

Middleware function to attach RequestDetail instance to the req object

Parameters:
NameTypeDescription
reqRequest

The Express request object

resResponse

The Express response object

nextNextFunction

The Express next function

Example
app.use(RequestDetail.middleware);