Skip to content

Instantly share code, notes, and snippets.

@Soul-Master
Last active August 23, 2019 23:23
Show Gist options
  • Save Soul-Master/ac2c304ca60d6aea7cc41791ab70e6d6 to your computer and use it in GitHub Desktop.
Save Soul-Master/ac2c304ca60d6aea7cc41791ab70e6d6 to your computer and use it in GitHub Desktop.
TypeScript Declaration file for Node.js package (server-timings) https://github.com/remy/server-timings
/// <reference types="node" />
declare module 'server-timings' {
import { RequestHandler, Request, Response, NextFunction } from 'express';
function ServerTimings(req: Request, res: Response, next: NextFunction): any;
module ServerTimings {
/**
* Record the start time
*/
export function start(label: string): void;
/**
* End the record time - if this isn't called, it will be called when the request is finished
*/
export function end(label: string): void;
}
export = ServerTimings;
}
// `server-timings` node package file
// https://github.com/remy/server-timings
module.exports = (req, res, next) => {
...
};
module.exports.start = opts => (req, res, next) => {
res.locals.timings.start(opts);
next();
};
module.exports.end = opts => (req, res, next) => {
res.locals.timings.end(opts);
next();
};
import * as express from 'express';
import * as timings from 'server-timings';
const app = express();
app.use(timings);
app.use(function (req, res, next) {
timings.start('Begin');
// Do something
timings.end('End');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment