Last active
August 23, 2019 23:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `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(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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