{"id":16036468,"url":"https://github.com/sajjadmrx/request-details","last_synced_at":"2025-03-18T03:32:38.486Z","repository":{"id":65522471,"uuid":"483644636","full_name":"sajjadmrx/request-details","owner":"sajjadmrx","description":"A Node.js package for handling request details in Express applications, extracting information such as user's IP, OS, browser, device, and CPU from user agent string in HTTP request headers","archived":false,"fork":false,"pushed_at":"2023-04-17T13:49:10.000Z","size":548,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-15T22:29:49.781Z","etag":null,"topics":["express","ip","nestjs","nodejs","requests","useragent"],"latest_commit_sha":null,"homepage":"https://sajjadmrx.github.io/request-details/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sajjadmrx.png","metadata":{"files":{"readme":"README.MD","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-20T12:26:21.000Z","updated_at":"2024-07-22T06:34:53.000Z","dependencies_parsed_at":"2023-01-27T05:45:18.842Z","dependency_job_id":null,"html_url":"https://github.com/sajjadmrx/request-details","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjadmrx%2Frequest-details","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjadmrx%2Frequest-details/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjadmrx%2Frequest-details/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjadmrx%2Frequest-details/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sajjadmrx","download_url":"https://codeload.github.com/sajjadmrx/request-details/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221706365,"owners_count":16867194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","ip","nestjs","nodejs","requests","useragent"],"created_at":"2024-10-08T22:04:46.543Z","updated_at":"2024-10-27T16:45:02.752Z","avatar_url":"https://github.com/sajjadmrx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# request-details\na 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.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/languages/top/sajjadmrx/request-details\" alt=\"languages\" \u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/sajjadmrx/request-details\"\u003e\n\u003c/p\u003e\n\n\n## ⌨️ Installation\n\n```bash\nnpm install request-details\n```\n\n## ⚙️ Usage\nTo 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:\n\n\n```js\n// CommonJS:\nconst RequestDetails = require('request-details').default;\n\nimport RequestDetails from 'request-details';\n\nimport express from \"express\";\n\nconst app = express();\n\napp.get(\"/\", (req, res) =\u003e {\n  const requestDetail = new RequestDetail(req);\n  // Get IP info\n  requestDetail.getIpInfo()\n    .then(ipInfo =\u003e {\n      console.log(ipInfo);\n      // { ip: '127.0.0.1', country: 'US', city: 'New York', ... }\n    })\n    .catch(err =\u003e {\n      console.error(err);\n    });\n\n  // Get OS info\n  const os = requestDetail.getOs();\n  console.log(os); // { name: 'Windows', version: '10' }\n\n  // Get browser info\n  const browser = requestDetail.getBrowser();\n  console.log(browser); // { name: 'Chrome', version: '58.0.3029.110' }\n\n  // Get device info\n  const device = requestDetail.getDevice();\n  console.log(device); // { type: 'desktop', vendor: 'Unknown', model: 'Unknown' }\n\n  // Get CPU info\n  const cpu = requestDetail.getCPU();\n  console.log(cpu); // { architecture: 'amd64' }\n\n  res.send(\"Hello world!\");\n});\n\napp.use(RequestDetails.middleware); // It will add the details to the request object (optional)\napp.get('/middleware', async (req, res, next) =\u003e {\n    const ipDetails = await req.info.getIpInfo()\n    res.json(ipDetails)\n})\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server is running on port 3000\");\n});\n\n```\n\n## 💡 Features\n\n* Retrieve IP address, operating system, and browser information from incoming HTTP requests.\n* Optional middleware to automatically add request details to the request object.\n* Simple and easy-to-use API with intuitive methods for retrieving request details.\n* Works with Express, NestJs, and other Node.js web frameworks.\n* Supports CommonJS and ES modules for importing in your project.\n\n## 🚀 API\n\n### `RequestDetail`\n* `constructor(req: Request, options?: Options)`: Creates an instance of the RequestDetail class with the Express request object and optional options to configure the instance.\n* `getIpInfo(): Promise\u003cI_iplocate\u003e`: Get information related to user's IP. Returns a Promise that resolves with the IP information.\n* `setOptions(options: Options): void`: Sets the options for the RequestDetail instance.\n* `getOs(): OS | null`: Get the operating system (OS) information from the user agent.\n* `getBrowser(): Browser | null`: Get the browser information from the user agent.\n* `getDevice(): Device | null`: Get the device information from the user agent.\n* `getCPU(): CPU | null`: Get the CPU information from the user agent.\n* `static fetchUserAgent(userAgent: string)`: Get user agent from a user agent string.\n* `static getIpInfoByIp(ip: string, token?: string): Promise\u003cI_iplocate\u003e`: Get IP information for a specific IP address.\n\n\n## 🤝 Contributing\nIf you would like to contribute to Request-Details, please open an issue or submit a pull request on the GitHub repository. 🔧💻🔍\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjadmrx%2Frequest-details","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsajjadmrx%2Frequest-details","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjadmrx%2Frequest-details/lists"}