# detective-cjs

> Get the dependencies of a CommonJS module by traversing its AST

Latest version **7.0.0** (published 2026-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install detective-cjs
pnpm add detective-cjs
yarn add detective-cjs
bun add detective-cjs
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-05-19 |
| First published | 2014-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=20.19.0 \|\| >=22.12.0 |
| Dependencies | 2 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Joel Kemp |
| Maintainers | pahen, mrjoelkemp, xhmikosr |
| Keywords | detective, commonjs, dependencies, ast, static analysis, cjs, jsx |

## Links

- npm: https://www.npmjs.com/package/detective-cjs
- Repository: https://github.com/dependents/node-detective-cjs
- Issues: https://github.com/dependents/node-detective-cjs/issues
- npm.io page: https://npm.io/package/detective-cjs

## Dependencies (2)

- [ast-module-types](https://npm.io/package/ast-module-types.md) ^7.0.0
- [node-source-walk](https://npm.io/package/node-source-walk.md) ^8.0.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 7.0.0 (latest) — 2026-05-19
- 6.1.1 — 2026-04-20
- 6.1.0 — 2026-03-03
- 6.0.1 — 2025-02-01
- 6.0.0 — 2024-04-14
- 5.0.1 — 2023-05-05
- 5.0.0 — 2023-05-05
- 4.1.0 — 2023-03-19
- 4.0.0 — 2022-03-03
- 3.1.3 — 2022-02-22
- 3.1.2 — 2022-02-21
- 3.1.1 — 2018-10-04
- 3.1.0 — 2018-09-25
- 3.0.0 — 2018-09-03
- 2.0.1 — 2018-08-24
- … 7 more at https://npm.io/package/detective-cjs/versions

## README

# detective-cjs

[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-detective-cjs/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-detective-cjs/actions/workflows/ci.yml?query=branch%3Amain)
[![npm version](https://img.shields.io/npm/v/detective-cjs?logo=npm&logoColor=fff)](https://www.npmjs.com/package/detective-cjs)
[![npm downloads](https://img.shields.io/npm/dm/detective-cjs)](https://www.npmjs.com/package/detective-cjs)

> Get the dependencies of a CommonJS module by traversing its AST

```sh
npm install detective-cjs
```

But dude, substack already built this: node-detective. Yes, but I needed the capability to reuse an AST
and this was unlikely to be merged timely. I can also support jsx and other syntactic constructs faster.

## Usage

```js
const fs = require('fs');
const detective = require('detective-cjs');

const mySourceCode = fs.readFileSync('myfile.js', 'utf8');

// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);

// Use skipLazyLoaded to only include top-level requires,
// treating inline (lazy-loaded) requires as intentional and legal
const topLevelOnly = detective(mySourceCode, { skipLazyLoaded: true });
```

* Supports JSX, ES7, and any other features that [node-source-walk](https://github.com/dependents/node-source-walk) supports.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/detective-cjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
