/request-info

Get information about an http request.

Primary LanguageJavaScriptMIT LicenseMIT

request-info NPM version NPM monthly downloads NPM total downloads

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

Install with npm (requires Node.js >=0.10.0):

$ npm install --save request-info

Usage

const info = require('request-info');
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  console.log(info(req)); // see below for details
});

API

Params

  • req {Object}: http request object (from http or express)
  • returns {Object}: info object containing httpVersion, ip, method, referer, url, and ua (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 }
  //   }
  // }
});

Acknowledgments

Some of the code has been adapted from https://github.com/joola/joola.io.express/blob/master/index.js#L39-L50

About

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

Related projects

You might also be interested in these projects:

Author

Brian Woodward

License

Copyright © 2021, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on July 20, 2021.