
Madge
Draws a graph of your JavaScript module dependencies and finds circular ones.
- Stars
- 10.2k
- Forks
- 349
- Licence
- MIT
- Language
- JavaScript
- Last update
- 10 months ago
- Type
- Dev tool
What it is
Madge reads your source code and works out which files import which others, then shows that as a visual graph. It can also list circular dependencies, orphaned files, and modules with no dependencies. It works with CommonJS, AMD and ES6 modules, and with Sass, Stylus and Less files.
- Run madge --circular on a source folder to list files that import each other in a loop
- Generate an SVG graph of a project's modules with the .image() API method
- Use --orphans to find files that nothing else imports
- Use --depends to see which modules rely on a given file before refactoring it
Great for
- JavaScript developers untangling a large codebase with many imports
- Teams who want to catch circular dependencies before they cause bugs
- Anyone who wants a picture of how a project's modules fit together
- Projects that use CSS preprocessors like Sass, Stylus or Less
Not ideal for
- Non-developers, since it runs from the command line or Node.js code
- Projects that need dependency analysis for languages other than those listed in the README
- Anyone wanting to generate images without Graphviz installed, since image output depends on it
How to get it
- 1
Install with a package manager
You'll need: Node.js and npm · Graphviz (optional, only for visual graph output)
Install madge globally with npm
npm -g install madgeInstall Graphviz on Mac OS X (optional)
brew install graphviz || port install graphvizInstall Graphviz on Ubuntu (optional)
apt-get install graphviz - 2
Run it
- Install madge with npm -g install madge
- Run madge path/src/app.js to list dependencies of one file
- Run madge --circular path/src/app.js to check for circular dependencies
- Optionally install Graphviz and use the .image() API to save a graph
- 3
Get the most out of it
- Use a .madgerc file or a madge key in package.json to set options such as fontSize and rankdir
- Use --extensions js,jsx to include more file types when scanning a folder
- Use excludeRegExp or dependencyFilter to leave out parts of the tree you do not need
- Use the API methods like circular(), orphans() and leaves() to build checks into scripts
Downloads
Strengths
- Supports several module systems (AMD, CommonJS, ES6) and CSS preprocessors
- Offers both a command-line tool and a Node.js API
- Has a configuration file option (.madgerc or package.json) for styling the graph
Trade-offs
- Image output requires Graphviz to be installed separately
- The README is truncated here, so details on newer module syntax support are unclear
- Relies on an external dependency-tree library for extraction, so edge cases depend on that library
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| madge (this) | 10.2k | Dev tool | beginner | 10 months ago | JavaScript developers untangling a large codebase with many imports |
| webpack-bundle-analyzer | 12.7k | Dev tool | beginner | 10 days ago | Frontend developers trying to shrink a slow-loading webpack bundle |
| webpack | 66k | Dev tool | intermediate | 4 days ago | Frontend developers building single-page or multi-page web apps |
| parcel | 44k | Dev tool | beginner | 4 days ago | Web developers who want a bundler that works without a config file |
| prettier | 52.4k | Dev tool | beginner | 4 days ago | Teams that want one shared code style without writing their own rules |
| babel | 44.1k | Dev tool | intermediate | 4 days ago | Web developers who want to use recent JavaScript syntax while still supporting older browsers |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.