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

needless

v0.1.1

Published

Remove modules from the require cache.

Downloads

8

Readme

                     _ _
 _ __   ___  ___  __| | | ___  ___ ___
| '_ \ / _ \/ _ \/ _` | |/ _ \/ __/ __|
| | | |  __/  __/ (_| | |  __/\__ \__ \
|_| |_|\___|\___|\__,_|_|\___||___/___/

This tiny little module allows you to remove modules from the require cache, easily and reasonably reliably. It can be used to do live code reloading in situations where the parent process must keep running. Works with JavaScript and CoffeeScript.

It's kind of a hack, so before dumping this in your project and calling it a day, read on!

When (not) to use this

As mentioned above, needless can be used when the parent process can't possibly be stopped. For instance, I use it to reload plugins for an IRC bot. If the bot's process would be restarted, it would have to reconnect to the server. People on IRC generally don't like blinkenbots.

So. Two genuine use cases for this module:

  1. Unit testing.
  2. Live code reloading if and only if there's No Other Way.

For unit testing, there are some really nice frameworks that do the same thing and more, like mockery and sandboxed-module.

If you don't really need to keep the parent process running, there are some great stable hot code reloading modules, like node-supervisor. But if you're reading this, you probably already know that.

Why (not) to use this

Reasons to use this module include "living dangerously" and "because I can", amongst others.

There are two good reasons not to use it:

  1. It's not officially supported. The require API is really stable ("Stability: 5 - Locked", in fact), but its internals might change, causing your software to explode and splatter broken bits all over your nice desktop wallpaper.
  2. If you have a complicated require chain (for example: another module required the same, now unloaded, module), it might behave unpredictably. Though if all you do is "a requires b requires c", you'll probably be OK.
  3. People on the internet will hate you.

OK, so I made that last one up.

How to use this

Easy! Let me show you using this hilariously contrived example!

// child.js
module.exports = 42;
// parent.js
var needlss = require('needless');

setInterval(function() {
  needless('./child');
  console.log(require('./child'));
}, 2000);

Now run parent.js:

$ node parent
42
42
42
(etc.)

Now, without stopping node, edit child.js. The node process should reflect the change:

42
42
<<< change child.js >>>
"Not 42"
"Not 42"
"Not 42"
(etc.)

"Wow Bob, that looks real easy!" "You betcha! And if you install within the next 5 minutes, we'll throw in a free .coffee!"

Why CoffeeScript?

Because I happen to like CoffeeScript, while it hilariously enrages some other people. I call that win-win. By the way: the usual argument against CoffeeScript is that it compiles into hard-to-read JavaScript (which is sometimes true, but more so if you write tricky CoffeeScript in the first place). Having said that, go and have a look at needless.js.

License

Simplified BSD (2-clause). See LICENSE.