memoryleak-express-middleware
v1.0.5
Published
This module is a easy way to setup Memory Leak Detector as a middleware on your project, so that you can hit a specific endpoint and retrieve the a digested Memory Leak Dump output out of it, on demand, when you want it. This will help you to identify pos
Downloads
4
Readme
MemoryLeak detector Middleware for Express with ES6
This module is a easy way to setup Memory Leak Detector as a middleware on your project, so that you can hit a specific endpoint and retrieve the a digested Memory Leak Dump output out of it, on demand, when you want it. This will help you to identify possible leaks on your app and avoid having memory leaks on your applications.
How does it work?
This module was designed to be a thin wrapper around memwatch-next and enable you to plug it into your existing ExpressJS app.
Implementation example:
const express = require('express');
const MemoryLeakExpressMiddleware = require('memoryleak-express-middleware');
const MEMORYLEAK_MIDDLEWARE_ENABLED = process.env.MEMORYLEAK_MIDDLEWARE_ENABLED;
const PORT = process.env.PORT || 16789;
const routes = express();
new MemoryLeakExpressMiddleware({MEMORYLEAK_MIDDLEWARE_ENABLED:MEMORYLEAK_MIDDLEWARE_ENABLED, routes:routes}).middleware();
routes.get('/', (req, res) => {
res.writeHead(200);
res.end('All done');
});
routes.listen(PORT, function (err) {
if (err) {
console.log("Got error when starting", err);
process.exit(1);
}
console.log("App started port ", PORT);
});
Options:
- The constructor enables you to provide options as arguments, and customize the behaviour of this module:
- MEMORYLEAK_MIDDLEWARE_ENABLED, set to false to disable. Default: false.
- logger, set your custom logger if you want. Default console.
- routes, set here your express app routes. Default null. Field required.
- routeName, set here the endpoint name you would like to set for getting dump diff. Default /memoryleak
- routeNameDump, set the endpoint name you would like to set for starting a new dump. Default /memoryleak-dump
- monitorLeaks, this will listen to leak events on memwatch. Useful if you would like to set leak events as errors, or if you would like to do anything else with it. Default: will log memory leaks as WARN.
- secret, this is a secret you may set in order to "protect" the endpoints from being hit by others. Default none.
Author
- Thomas Modeneis
- StackOverflow
Contributors
- Homero Valle
License
This module is licensed under the MIT license.