Get information about an http request.
Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.
Install with npm (requires Node.js >=0.10.0):
$ npm install --save request-info
const info = require('request-info');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log(info(req)); // see below for details
});
Params
req
{Object}: http request object (from http or express)returns
{Object}: info object containinghttpVersion
,ip
,method
,referer
,url
, andua
(useragent information)
Example
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log(info(req));
// {
// httpVersion: '1.1',
// ip: '127.0.0.1',
// method: 'GET',
// referer: 'http://localhost:8080/index.html',
// url: '/',
// ua: {
// ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
// browser: { name: 'Chrome', version: '52.0.2743.116', major: '52' },
// engine: { version: '537.36', name: 'WebKit' },
// os: { name: 'Mac OS', version: '10.9.5' },
// device: { model: undefined, vendor: undefined, type: undefined },
// cpu: { architecture: undefined }
// }
// }
});
Some of the code has been adapted from https://github.com/joola/joola.io.express/blob/master/index.js#L39-L50
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
- generate-webtask: Generate a starting point for a webtask.io service. | homepage
- gh-clone: git clone a repo with only username/repo, or if it's an NPM package you can… more | homepage
- gulp-bundle-webtask: Gulp plugin for browserifying and bundling your source code before deploying to webtask.io. | homepage
Brian Woodward
Copyright © 2021, Brian Woodward. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on July 20, 2021.