Git Product home page Git Product logo

express-utils's Introduction

Free To Play Express Utils

Dependencies

This package assumes a node express application using node-app-base.

Contents

  • middleware for adding request metrics
  • augment application logs with request and session IDs

Adding request ID and Session ID to application logs

In the entry point to the application (before passing the logger to any modules), request the logger and initialise using the node-app-base logger. Pass the wrapped logger to any modules that require a logger.

const createRequestLogger = require('express-utils').createRequestLogger;

const {
    config, timers, metrics, logger,
} = require('node-app-base')('my-app');

const requestLogger = createRequestLogger(logger);

const app = require('./app')(
    requestLogger,
);

Once the express app is created, create storeIdsMiddleware and load into the application. If you are using session middleware, make sure the session comes before storing the Ids:

const app = express();

const sessionMiddleware = session();
const storeIdsMiddleware = require('express-utils').createStoreIdsMiddleware();

app.use(sessionMiddleware)
app.use(storeIdsMiddleware);

Including metrics middleware

Pass logger, metrics and timers, along with instructions for linearBuckets to the metricsMiddleware and attach using app.use.


const app = express();

const metricsMiddleware = require('express-utils').createMetricsMiddleware(logger, metrics, timers, [5, 5, 5]);

app.use(metricsMiddleware);

express-utils's People

Contributors

benbrunton avatar jamesbarwell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.