Constructor
new RequestDetail(req, options)
Creates an instance of the RequestDetails
class.
Parameters:
Name | Type | Description |
---|---|---|
req | Request | The Express request object. |
options | Options | The options to configure the |
Members
(static) fetchUserAgent
Get user agent.
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:
Name | Type | Description |
---|---|---|
options | Options | The options to set. |
Returns:
- Type:
- void
(static) getIpInfoByIp(ip, token) → {Promise.<I_iplocate>}
Get IP information for a specific IP address
Parameters:
Name | Type | Description |
---|---|---|
ip | string | The IP address |
token | string | | 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:
Name | Type | Description |
---|---|---|
req | Request | The Express request object |
res | Response | The Express response object |
next | NextFunction | The Express next function |
Example
app.use(RequestDetail.middleware);