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

@yunnysunny/request-logging

v0.15.1

Published

Print the express request log to console and save it to kafka when required, and even can send alram message when the response code greater than 500.

Downloads

30

Readme

request-logging

Print the express request log to console and save it to kafka and mongodb when required, and even can send alram message when the response code greater than 500.

npm version build status David deps Test coverage node version

Installation

npm install @yunnysunny/request-logging --save

Usage

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const requestLog = require('@yunnysunny/request-logging');

const app = express();
app.enable('trust proxy');

// view engine setup
app.set('port', port);
app.use(requestLog());

app.use(bodyParser.json({limit: '1mb'}));
app.use(bodyParser.urlencoded({
    extended: false,
    limit: '1mb'
}));

API

See api document.

Fields

If you want to save request logging to mongodb, this is the fields description, which you will used to create a mongoose schema:

| name | type | description | | -------------- | ------ | ------------------------------------------------------------ | | hostname | String | The domain of current server. | | original_url | String | The original url contains query string. | | path | String | The request path doesn't contain query string. | | user_agent | String | The user agent. | | custom_headers | Object | The specific you wanna save. | | method | String | The http request method. | | ip | String | The client's ip. | | host | String | The server's ip. | | duration | Number | The millisecond the request costed. | | pid | Number | The server's process id. | | req_id | Number | The inner request number, auto increased when new request come. | | content_length_req | Number | The content-length of the request headers. | | content_length | Number | The content-length of the response headers. | | status_code | Number | The status code of current HTTP response. | | res_code | Number | The inner response code, which will be got from the response header of res-code. | | res_data | Object | The reponse data. | | req_time | Number | The timestamp of begin time of current request occured. | | req_time_string| String | The time of begin time, formated in ISO 8601 Extended Format. | | req_data | Object | The request data, which would form query string or form data. | | referer | String | The HTTP referer header. | | session | Object | The session of current request. | | aborted | Boolean| Whether the request has aborted. |

We suggest you use such mongoose schema, which is compatible when the fields is changed:

const {Schema} = require('mongoose');

const requestLogSchema =  new Schema({
    req_time: Date
},{ 
    timestamps: {
        createdAt: 'created_at',
        updatedAt : 'updated_at'
    },
    strict: false
});
module.exports = requestLogSchema;

License

MIT