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

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:
  1. MEMORYLEAK_MIDDLEWARE_ENABLED, set to false to disable. Default: false.
  2. logger, set your custom logger if you want. Default console.
  3. routes, set here your express app routes. Default null. Field required.
  4. routeName, set here the endpoint name you would like to set for getting dump diff. Default /memoryleak
  5. routeNameDump, set the endpoint name you would like to set for starting a new dump. Default /memoryleak-dump
  6. 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.
  7. secret, this is a secret you may set in order to "protect" the endpoints from being hit by others. Default none.

Author

Contributors

  • Homero Valle

License

This module is licensed under the MIT license.