Gathering detailed insights and metrics for madge
Gathering detailed insights and metrics for madge
Gathering detailed insights and metrics for madge
Gathering detailed insights and metrics for madge
@types/madge
TypeScript definitions for madge
grunt-madge
Check for circular dependencies in AMD or CommonJS modules using Madge.
@diazoxide/nx-madge
This library was generated with [Nx](https://nx.dev).
@madgex/design-system
A work-in progress Design System for building a UI for Madgex products.
Create graphs from your CommonJS, AMD or ES6 module dependencies
npm install madge
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (93.97%)
Shell (2.27%)
TypeScript (2.16%)
Vue (1.59%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
9,608 Stars
534 Commits
334 Forks
51 Watchers
5 Branches
54 Contributors
Updated on Jul 11, 2025
Latest Version
8.0.0
Package Id
madge@8.0.0
Unpacked Size
102.60 kB
Size
33.73 kB
File Count
140
NPM Version
9.3.1
Node Version
18.14.0
Published on
Aug 05, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
12
1
Madge is a developer tool for generating a visual graph of your module dependencies, finding circular dependencies, and giving you other useful info. Joel Kemp's awesome dependency-tree is used for extracting the dependency tree.
Read the changelog for latest changes.
I've worked with Madge on my free time for the last couple of years and it's been a great experience. It started as an experiment but turned out to be a very useful tool for many developers. I have many ideas for the project and it would definitely be easier to dedicate more time to it with some financial support 🙏
Regardless of your contribution, thanks for your support!
Graph generated from madge's own code and dependencies.
A graph with circular dependencies. Blue has dependencies, green has no dependencies, and red has circular dependencies.
1npm -g install madge
Graphviz is only required if you want to generate visual graphs (e.g. in SVG or DOT format).
1brew install graphviz || port install graphviz
1apt-get install graphviz
path
is a single file or directory, or an array of files/directories to read. A predefined tree can also be passed in as an object.
config
is optional and should be the configuration to use.
Returns a
Promise
resolved with the Madge instance object.
Returns an
Object
with all dependencies.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.obj()); 5});
Returns an
Object
of warnings.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.warnings()); 5});
Returns an
Array
of all modules that have circular dependencies.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.circular()); 5});
Returns an
Object
with only circular dependencies.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.circularGraph()); 5});
Returns an
Array
of all modules that depend on a given module.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.depends('lib/log.js')); 5});
Return an
Array
of all modules that no one is depending on.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.orphans()); 5});
Return an
Array
of all modules that have no dependencies.
1const madge = require('madge'); 2 3madge('path/to/app.js').then((res) => { 4 console.log(res.leaves()); 5});
Returns a
Promise
resolved with a DOT representation of the module dependency graph. SetcircularOnly
to only include circular dependencies.
1const madge = require('madge'); 2 3madge('path/to/app.js') 4 .then((res) => res.dot()) 5 .then((output) => { 6 console.log(output); 7 });
Write the graph as an image to the given image path. Set
circularOnly
to only include circular dependencies. The image format to use is determined from the file extension. Returns aPromise
resolved with a full path to the written image.
1const madge = require('madge'); 2 3madge('path/to/app.js') 4 .then((res) => res.image('path/to/image.svg')) 5 .then((writtenImagePath) => { 6 console.log('Image written to ' + writtenImagePath); 7 });
Return a
Promise
resolved with the XML SVG representation of the dependency graph as aBuffer
.
1const madge = require('madge'); 2 3madge('path/to/app.js') 4 .then((res) => res.svg()) 5 .then((output) => { 6 console.log(output.toString()); 7 });
Property | Type | Default | Description |
---|---|---|---|
baseDir | String | null | Base directory to use instead of the default |
includeNpm | Boolean | false | If shallow NPM modules should be included |
fileExtensions | Array | ['js'] | Valid file extensions used to find files in directories |
excludeRegExp | Array | false | An array of RegExp for excluding modules |
requireConfig | String | null | RequireJS config for resolving aliased modules |
webpackConfig | String | null | Webpack config for resolving aliased modules |
tsConfig | String|Object | null | TypeScript config for resolving aliased modules - Either a path to a tsconfig file or an object containing the config |
layout | String | dot | Layout to use in the graph |
rankdir | String | LR | Sets the direction of the graph layout |
fontName | String | Arial | Font name to use in the graph |
fontSize | String | 14px | Font size to use in the graph |
backgroundColor | String | #000000 | Background color for the graph |
nodeShape | String | box | A string specifying the shape of a node in the graph |
nodeStyle | String | rounded | A string specifying the style of a node in the graph |
nodeColor | String | #c6c5fe | Default node color to use in the graph |
noDependencyColor | String | #cfffac | Color to use for nodes with no dependencies |
cyclicNodeColor | String | #ff6c60 | Color to use for circular dependencies |
edgeColor | String | #757575 | Edge color to use in the graph |
graphVizOptions | Object | false | Custom Graphviz options |
graphVizPath | String | null | Custom Graphviz path |
detectiveOptions | Object | false | Custom detective options for dependency-tree and precinct |
dependencyFilter | Function | false | Function called with a dependency filepath (exclude subtrees by returning false) |
You can use configuration file either in .madgerc
in your project or home folder or directly in package.json
. Look here for alternative locations for the file.
.madgerc
1{ 2 "fontSize": "10px", 3 "graphVizOptions": { 4 "G": { 5 "rankdir": "LR" 6 } 7 } 8}
package.json
1{ 2 "name": "foo", 3 "version": "0.0.1", 4 ... 5 "madge": { 6 "fontSize": "10px", 7 "graphVizOptions": { 8 "G": { 9 "rankdir": "LR" 10 } 11 } 12 } 13}
List dependencies from a single file
1madge path/src/app.js
List dependencies from multiple files
1madge path/src/foo.js path/src/bar.js
List dependencies from all *.js files found in a directory
1madge path/src
List dependencies from multiple directories
1madge path/src/foo path/src/bar
List dependencies from all *.js and *.jsx files found in a directory
1madge --extensions js,jsx path/src
Finding circular dependencies
1madge --circular path/src/app.js
Show modules that depends on a given module
1madge --depends wheels.js path/src/app.js
Show modules that no one is depending on
1madge --orphans path/src/
Show modules that have no dependencies
1madge --leaves path/src/
Excluding modules
1madge --exclude '^(foo|bar)\.js$' path/src/app.js
Save graph as a SVG image (requires Graphviz)
1madge --image graph.svg path/src/app.js
Save graph with only circular dependencies
1madge --circular --image graph.svg path/src/app.js
Save graph as a DOT file for further processing (requires Graphviz)
1madge --dot path/src/app.js > graph.gv
Using pipe to transform tree (this example will uppercase all paths)
1madge --json path/src/app.js | tr '[a-z]' '[A-Z]' | madge --stdin
To enable debugging output if you encounter problems, run madge with the
--debug
option then throw the result in a gist when creating issues on GitHub.
1madge --debug path/src/app.js
1npm install 2npm test
1npm run release
It could happen that the files you're not seeing have been skipped due to errors or that they can't be resolved. Run madge with the --warning
option to see skipped files. If you need even more info run with the --debug
option.
Madge uses dependency-tree which uses filing-cabinet to resolve modules. However it requires configurations for each file type (js/jsx) and (ts/tsx). So provide both webpackConfig
and tsConfig
options to madge.
Only one syntax is used by default. You can use both though if you're willing to take the degraded performance. Put this in your madge config to enable mixed imports.
For ES6 + CommonJS:
1{ 2 "detectiveOptions": { 3 "es6": { 4 "mixedImports": true 5 } 6 } 7}
For TypeScript + CommonJS:
1{ 2 "detectiveOptions": { 3 "ts": { 4 "mixedImports": true 5 } 6 } 7}
import type
statements in ES6 + Flow?Put this in your madge config.
1{ 2 "detectiveOptions": { 3 "es6": { 4 "skipTypeImports": true 5 } 6 } 7}
import
in type annotations in TypeScript?Put this in your madge config.
1{ 2 "detectiveOptions": { 3 "ts": { 4 "skipTypeImports": true 5 } 6 } 7}
Put this in your madge config.
1{ 2 "detectiveOptions": { 3 "ts": { 4 "skipAsyncImports": true 5 }, 6 "tsx": { 7 "skipAsyncImports": true 8 } 9 } 10}
Note: tsx
is optional, use this when working with JSX.
Ensure you have this in your .tsconfig
file.
1{ 2 "compilerOptions": { 3 "module": "commonjs", 4 "allowJs": true 5 } 6}
Ensure you have installed Graphviz. If you're running Windows, note that Graphviz is not added to the PATH
variable during install. You should add the folder of gvpr.exe
(typically %Graphviz_folder%/bin
) to the PATH
variable manually.
Homebrew doesn't include GTS by default. Fix this by doing:
1brew uninstall graphviz 2brew install gts 3brew install graphviz
Try running madge with a different layout, here's a list of the ones you can try:
dot "hierarchical" or layered drawings of directed graphs. This is the default tool to use if edges have directionality.
neato "spring model'' layouts. This is the default tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.
fdp "spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy.
sfdp multiscale version of fdp for the layout of large graphs.
twopi radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node.
circo circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks.
This project exists thanks to all the people who contribute.
Thanks to the awesome people below for making donations! 🙏Donate
MIT License
0/10
Summary
Madge vulnerable to command injection
Affected Versions
< 4.0.1
Patched Versions
4.0.1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/12 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More