nodejs-dep-check
installation
$ npm install --save-dev nodejs-dep-check
description
this module checks to see if all the dependencies in your code are reflected in package.json
- you may have noticed that when you deploy code the build sometimes fails, or worse, after you deploy there's a runtime error because a require statement in your code references a dependency that didn't make into package.json for whatever reason.
therefore, ndc (nodejs-dep-check) should be incorporated in your continuous integration tests - this module is designed to be used as a static analysis test
you probably won't want this module for anything but testing, so you can use the --save-dev
option instead of --save
when
installing with NPM
how to use
from the command line:
$ n-dc
or
$ n-dc --conf path/to/ndc.conf.js --pkg.json path/to/package.json
use from anywhere in Node.js:
var ndc = ; ndc;
note: you can ignore specific files by using either the ignoreDirs or ignorePaths options, just use '.js' with the filename
usage with Mocha
;
It's probably best used with a testing framework like Mocha, but you can also use it from the command line.
Caveats:
(1) Make sure the CWD is the root of your project (aka, you issue the node or mocha command where your package.json file is) (2) This module unfortunately cannot help you with dynamically resolved require calls (aka, require(path.resolve('foo' + '/bar')))
This module is configured by default to look at your entire project, so it always starts recursively with the root of your app.
here's typical output - you might notice that there is a line commented out
//var redis = require('redis');
this library doesn't ignore commented out lines - so you may wish to alter the comment into this:
//var redis = require#('redis'); (or whatever non-alpha-numeric character suits your fancy)
any questions you can open an issue on Github or email me at alex@oresoftware.com, thanks