reqursive
Take a file and recursively discover all the files loaded in using require()
.
Installation
$ npm install reqursive
Usage
Call reqursive
on a file, and soon after you'll get an array containing
a list of all the scripts that file requires before running.
var worker =async =
You might have noticed that reqursive steers clear of the insides of node_modules
by default. By passing the traverseModules
option as true you'll get back
not only the modules, but their contents as well:
var async =reqursive =
You can pass in an array of files to evaluate them together - they don't have to be connected, but they can be. If the files are from separate directories, the returned paths will be relative to the first file by default.
If you're looking to just get the files required by a single script, you can
use reqursive.children()
:
var reqursive =filename = requirereqursive
File Properties
The reqursive
and reqursive.children
methods return an array of file
objects, each with the following properties:
-
id
: Either the name of the module or the name of the file, e.g.http
orindex.js
-
filename
: The path to the file. When usingreqursive
, this is relative to the original file. When usingreqursive.children
, the path is absolute. -
module
: true if the file is a module: taken fromnode_modules
, or a part of Node's core. -
native
: true if the file is a native module, e.g.http
ornet
, but notrequest
orbrowserify
. -
parents
: An array of scripts that require this file. -
mgroup
: This is equal to the id of the module this file is a part of. Top-level scripts, i.e. not part of a module, will have an "mgroup" equal to "false". -
error
: If a syntax error was picked up when parsing this file, it'll go here. Handle this however you please.
Options
The following only apply to reqursive
, not reqursive.children
-
traverseModules
: Don't stop when hitting a module - keep going through the module's files too. -
absolute
: Return absolute paths instead of relative.