Skip to content

catdad/runtime-required

Repository files navigation

runtime-required

travis score-codeclimate npm-downloads npm-version dm-david

Haven't you ever always needed to know what files are being required by your app? Okay, maybe not always, but once? No? Just me? Fine, move along then. But in case you need it, here's how it all works:

Install

It's in npm, of course:

npm install runtime-required

Usage

require('runtime-required') → EventEmitter

Yup, you just include it in your project and it exposes an event emitter. There is only a single file event, and it has the following properties:

  • type {string}: one of
    • builtin (node's default modules)
    • module (ones that appear inside the node_modules directory)
    • file (from your own project... or I guess elsewhere on the filesystem)
  • id {string}: the identifier for this module. For module and file types, it will be a fully-resolved file path. For builtin types, it will be the name of the module.

Example

const required = require('runtime-required');

required.on('file', data => {
  console.log(`a ${data.type} module was required at "${data.id}"`);
});