npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-req-logger

v1.0.7

Published

HTTP request logger middleware for Express.

Downloads

7

Readme

express-req-logger

HTTP request logger middleware for Express.

usage

npm i -S express-req-logger
const express = require('express');
const logger = require('express-req-logger');

var app = express();

app.use(logger());

// GET / HTTP/1.1 200 367ms

API

logger(format, option)

The format argument is a string, either 'tiny','normal', 'long', or something like that ':method :url HTTP/:httpVersion :status :duration'.

format

normal Default style.

GET / HTTP/1.1 200 218ms

tiny Short style.

GET / 200

long Long style.

[2017-05-14 21:03:25 周日] ::ffff:192.168.0.100 /index.html HTTP/1.1 304 23ms Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

:method

HTTP request method. GET

:url

Request path. /index.html

:httpVersion

HTTP version number. 1.1

:status

Request status code. 200

:duration

Request to respond to the duration of the unit, in milliseconds. 263ms

:ip

Remote client IP address. ::ffff:192.168.0.100

:date

Current date. 2017-05-14

:time

Current time. 19:00:00

:day

Current week. 周日

:userAgent

Remote client user agent content.

const logger = require('express-req-logger');
var app = require('express')();

app.use(logger(
    '[:date :time] :method :url HTTP/:httpVersion :status'
));

// [2017-05-14 19:23:33] GET /index.html HTTP/1.1 200

option

Used to modify the output of a field, or to add a field.

app.use(logger(
    '[:date :when :time] :method :url'
), {

  // Add the new when field and add it to the format parameter.
  when: function (req, res) { // Can receive request and response object.
    return (new Date().getHours() >= 12) ? 'PM' : 'AM';
  },

  // Rewrite the method function
  method: function (req, res) {
    return req.method.toLowerCase();
  }

});

// [2017-05-14 上午 10:22:29] get /index.html

express-req-logger

Express的HTTP请求日志中间件

使用方法

npm i -S express-req-logger
const express = require('express');
const logger = require('express-req-logger');

var app = express();

app.use(logger());

接口

logger(format, option)

format参数是一个字符串,可以是预设的配置'tiny''normal''long'或者是类似':method :url HTTP/:httpVersion :status :duration'

format

normal 默认风格。如下所示

GET / HTTP/1.1 200 218ms

tiny 简短风格

GET / 200

long 长风格

[2017-05-14 21:03:25 周日] ::ffff:192.168.0.100 /index.html HTTP/1.1 304 23ms Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

:method

HTTP请求方法。GET

:url

请求路径。/index.html

:httpVersion

HTTP版本。1.1

:status

请求状态码。200

:duration

请求到响应持续的时间,单位为毫秒。263ms

:ip

客户端IP地址。::ffff:192.168.0.100

:date

当前日期。2017-05-14,本项目首次提交时间。

:time

当前时间。19:00:00

:day

当前星期。周日

:userAgent

客户端用户代理内容。

const logger = require('express-req-logger');
var app = require('express')();

app.use(logger(
    '[:date :time] :method :url HTTP/:httpVersion :status'
));

// [2017-05-14 19:23:33] GET /index.html HTTP/1.1 200

option

用于修改字段的输出,或增加字段。

app.use(logger(
    '[:date :when :time] :method :url'
), {

  // 自己增加新的when字段,并加入到format参数中。
  when: function (req, res) { // 可接收到request和response对象。
    return (new Date().getHours() >= 12) ? '下午' : '上午';
  },

  // 重写method方法
  method: function (req, res) {
    return req.method.toLowerCase();
  }
  
});

// [2017-05-14 上午 10:22:29] get /index.html