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

drex

v0.1.4

Published

drex - 'dynamic require() extension'. Dynamic version of Node's require() - loads fresh copy of the module every time the module file is changed.

Downloads

10

Readme

drex

drex - "dynamic require() extension". Dynamic version of Node's require() - loads fresh copy of the module every time the module file is changed.

Insanely simple, and/but astonishingly useful grab of bits, which has been brought to this world out of severe necessity.

Here is why:

  • all re-loaders I was able to find reload the whole node process, which means that the context of the process is gone;
  • but, sometimes, you don't want that! You want your process to continue running intact, at least for those clients who already deep in it, and would choke if process forgets about them;
  • sometime you have a little (or BIG) piece of code which you constantly change and, for G-d sake, do not want to sacrifice the whole your Node process for, but
  • you don't want to loose the benefits of CommonJS/require supported modularity of your code.

Here comes drex, and it comes like this:

var drex = require('drex');

... node code node code node code ...

// here goes my frea[ky/quently updated] piece of code, which lives in a js file called mucode.js:
drex.require('./mucode.js', function(mucode)
{
  // at this point my mucode.js has been require()d, just like this: 
  // var mucode = require('./mucode.js');
  // the code of the required module is the LATEST UPDATE TO mucode.js
  mucode.muNewFunc();  
});

#Here is an example (and the reason I had to comeup with drex) from the real life when drex is irreplaceable:# frequently updated/added socket.io event handlers:

io.sockets.on('connection', function (socket) {
  // I need to do many things here, and these things change all the time!
  // If I use something like "forever", or "supervisor" to re-start my Node process every time 
  // when things here should change, all active sessions will be killed!
  // Oh, no, no, no!
  // All I want to do here, most of the time, is to put new event handler, which existing sessions 
  // do not even know about!
  
  drex.require('./my_module_with_event_handlers_which_I_always_change.js', function(mymod) {
      // here I can start calling methods from my module like there is no tomorrow!
      // and I'm guaranteed that every time I update my module, sessions which will come here after the update
      // will get the new code, but sessions which were opened before the update will still be working with the
      // code which existed in my module when these sessions were created. That's fair!
  });

#Installation# npm install drex

#TL;DR;# drex is watching a module for updates and cleanly re-requires the module after the update. New code is being require()d as if the new code is a totally different module, so require.cache is not a problem.

Enjoy