@mt0926/node-network-devtools 0.2.0 β 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -109
- package/README.zh-CN.md +62 -108
- package/dist/cjs/adapters/axios.js +2 -0
- package/dist/cjs/adapters/axios.js.map +1 -0
- package/dist/cjs/adapters/nextjs.js +133 -0
- package/dist/cjs/adapters/nextjs.js.map +1 -0
- package/dist/cjs/config.js +150 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/context/context-manager.js +139 -0
- package/dist/cjs/context/context-manager.js.map +1 -0
- package/dist/cjs/gui/browser-detector.js +263 -0
- package/dist/cjs/gui/browser-detector.js.map +1 -0
- package/dist/cjs/gui/browser-launcher.js +365 -0
- package/dist/cjs/gui/browser-launcher.js.map +1 -0
- package/dist/cjs/gui/event-bridge.js +197 -0
- package/dist/cjs/gui/event-bridge.js.map +1 -0
- package/dist/cjs/gui/port-utils.js +85 -0
- package/dist/cjs/gui/port-utils.js.map +1 -0
- package/dist/cjs/gui/server.js +267 -0
- package/dist/cjs/gui/server.js.map +1 -0
- package/dist/cjs/gui/websocket-hub.js +336 -0
- package/dist/cjs/gui/websocket-hub.js.map +1 -0
- package/dist/cjs/index.js +170 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interceptors/http-patcher.js +275 -0
- package/dist/cjs/interceptors/http-patcher.js.map +1 -0
- package/dist/cjs/interceptors/undici-patcher.js +362 -0
- package/dist/cjs/interceptors/undici-patcher.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/register.js +95 -0
- package/dist/cjs/register.js.map +1 -0
- package/dist/cjs/store/ring-buffer.js +241 -0
- package/dist/cjs/store/ring-buffer.js.map +1 -0
- package/dist/cjs/test-setup.js +8 -0
- package/dist/cjs/test-setup.js.map +1 -0
- package/dist/cjs/utils/module-compat.js +83 -0
- package/dist/cjs/utils/module-compat.js.map +1 -0
- package/dist/esm/gui/server.js +41 -6
- package/dist/esm/gui/server.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/interceptors/undici-patcher.js +9 -4
- package/dist/esm/interceptors/undici-patcher.js.map +1 -1
- package/dist/esm/utils/module-compat.js +78 -0
- package/dist/esm/utils/module-compat.js.map +1 -0
- package/dist/gui/assets/index.css +1 -1
- package/dist/gui/assets/index.js +10 -10
- package/dist/types/gui/server.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interceptors/undici-patcher.d.ts.map +1 -1
- package/dist/types/utils/module-compat.d.ts +34 -0
- package/dist/types/utils/module-compat.d.ts.map +1 -0
- package/package.json +42 -35
- package/dist/esm/cli.js +0 -203
- package/dist/esm/cli.js.map +0 -1
- package/dist/types/cli.d.ts +0 -8
- package/dist/types/cli.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# π Node Network DevTools
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**A powerful, zero-config network debugging companion for Node.js.**
|
|
6
|
+
*Monitor all outgoing HTTP, HTTPS, and Fetch/Undici requests in a sleek, real-time Web GUI that feels just like Chrome DevTools.*
|
|
6
7
|
|
|
7
|
-
[](https://www.npmjs.com/package/@mt0926/node-network-devtools)
|
|
8
|
+
[](https://www.npmjs.com/package/@mt0926/node-network-devtools)
|
|
8
9
|
[](https://opensource.org/licenses/MIT)
|
|
9
|
-
[](https://nodejs.org)
|
|
10
10
|
|
|
11
11
|
[English](#) | [δΈζζζ‘£](./README.zh-CN.md)
|
|
12
12
|
|
|
@@ -14,151 +14,104 @@
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## π Why Node Network DevTools?
|
|
18
18
|
|
|
19
|
-
**
|
|
20
|
-
|
|
21
|
-
- Uses Puppeteer to launch a minimal browser window for the GUI
|
|
22
|
-
- Intercepts all network requests which may impact performance
|
|
23
|
-
- Stores request/response data in memory
|
|
24
|
-
- Not suitable for production workloads
|
|
25
|
-
|
|
26
|
-
### Disabling in Production
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
// Conditional installation
|
|
30
|
-
if (process.env.NODE_ENV === 'development') {
|
|
31
|
-
await install();
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Or use environment variables:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Disable GUI and auto-open
|
|
39
|
-
NND_GUI_ENABLED=false NND_AUTO_OPEN=false node your-app.js
|
|
40
|
-
```
|
|
19
|
+
Tired of `console.log`ing every request and response? **Node Network DevTools** brings the familiarity of the browser's "Network" tab to your Node.js backend. Whether you're debugging external API calls, microservices, or Next.js server actions, you can now inspect every detail in real-time.
|
|
41
20
|
|
|
42
21
|
## β¨ Features
|
|
43
22
|
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
- π **Request Tracing** -
|
|
49
|
-
- π‘οΈ **
|
|
50
|
-
- β‘ **
|
|
51
|
-
- π¦ **
|
|
23
|
+
- π **DevTools-like Experience** - A familiar, responsive Web GUI for inspecting headers, payloads, and responses.
|
|
24
|
+
- π **Universal Interception** - Native support for `http/https` modules and modern `fetch/undici` (Node.js 18+).
|
|
25
|
+
- π οΈ **Zero Code Intrusion** - Plug it into your project with a single line of code or a simple CLI flag.
|
|
26
|
+
- π₯οΈ **Minimal Browser Window** - Automatically launches a compact, app-mode GUI window (using your system's Chrome, Edge, or Chromium).
|
|
27
|
+
- π **Smart Request Tracing** - Automatically correlate related requests in a single business flow using `AsyncLocalStorage`.
|
|
28
|
+
- π‘οΈ **Built-in Redaction** - Keeps your secrets safe by auto-redacting sensitive headers like `Authorization` and `Cookie`.
|
|
29
|
+
- β‘ **Framework Ready** - Seamless integration with Next.js, Express, Fastify, and more.
|
|
30
|
+
- π¦ **Dual Module Support** - Works out of the box with both **ESM** and **CommonJS**.
|
|
52
31
|
|
|
53
32
|
## πΈ Screenshots
|
|
54
33
|
|
|
55
34
|
### Web GUI Interface
|
|
56
35
|

|
|
57
36
|
|
|
58
|
-
### Chrome DevTools Integration
|
|
59
|
-

|
|
60
|
-
|
|
61
37
|
## π Quick Start
|
|
62
38
|
|
|
63
|
-
### Installation
|
|
39
|
+
### 1. Installation
|
|
64
40
|
|
|
65
41
|
```bash
|
|
66
|
-
npm install node-network-devtools
|
|
42
|
+
npm install @mt0926/node-network-devtools
|
|
67
43
|
# or
|
|
68
|
-
pnpm add node-network-devtools
|
|
69
|
-
# or
|
|
70
|
-
yarn add node-network-devtools puppeteer
|
|
44
|
+
pnpm add @mt0926/node-network-devtools
|
|
71
45
|
```
|
|
72
46
|
|
|
73
|
-
**Note**:
|
|
74
|
-
|
|
75
|
-
### Usage
|
|
47
|
+
> **Note**: No extra dependencies like Puppeteer are required! It uses your system's existing browser.
|
|
76
48
|
|
|
77
|
-
|
|
49
|
+
### 2. Usage (Recommended)
|
|
78
50
|
|
|
79
|
-
|
|
80
|
-
npx node-network-devtools your-script.js
|
|
81
|
-
# or use the short alias
|
|
82
|
-
npx nnd your-script.js
|
|
83
|
-
```
|
|
51
|
+
Just call `install()` at the very beginning of your application entry point.
|
|
84
52
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
53
|
+
**ESM:**
|
|
54
|
+
```typescript
|
|
55
|
+
import { install } from '@mt0926/node-network-devtools';
|
|
88
56
|
|
|
89
|
-
|
|
90
|
-
node -r node-network-devtools/register your-script.js
|
|
57
|
+
await install(); // Call before any other imports that make network requests
|
|
91
58
|
```
|
|
92
59
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
import { install } from 'node-network-devtools';
|
|
97
|
-
|
|
98
|
-
await install();
|
|
60
|
+
**CommonJS:**
|
|
61
|
+
```javascript
|
|
62
|
+
const { install } = require('@mt0926/node-network-devtools');
|
|
99
63
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// ...
|
|
64
|
+
(async () => {
|
|
65
|
+
await install();
|
|
66
|
+
})();
|
|
104
67
|
```
|
|
105
68
|
|
|
106
|
-
###
|
|
107
|
-
|
|
108
|
-
After starting your application:
|
|
69
|
+
### 3. Advanced: Zero-Code Injection
|
|
109
70
|
|
|
110
|
-
|
|
111
|
-
- Compact window size (800x600 by default)
|
|
112
|
-
- Customizable window size and title
|
|
113
|
-
- No browser chrome or toolbars (app mode)
|
|
71
|
+
If you don't want to modify your source code, you can use Node.js CLI arguments to inject the tool.
|
|
114
72
|
|
|
115
|
-
|
|
73
|
+
**ESM:**
|
|
74
|
+
```bash
|
|
75
|
+
node --import @mt0926/node-network-devtools/register your-script.js
|
|
116
76
|
```
|
|
117
|
-
|
|
77
|
+
|
|
78
|
+
**CommonJS:**
|
|
79
|
+
```bash
|
|
80
|
+
node -r @mt0926/node-network-devtools/register your-script.js
|
|
118
81
|
```
|
|
119
82
|
|
|
120
83
|
## π₯οΈ Web GUI
|
|
121
84
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Minimal Browser Window
|
|
125
|
-
|
|
126
|
-
The GUI opens in a minimal Puppeteer-controlled browser window:
|
|
127
|
-
|
|
128
|
-
- **Compact Size**: Default 800x600, customizable via environment variables
|
|
129
|
-
- **App Mode**: No browser chrome, toolbars, or address bar
|
|
130
|
-
- **Custom Title**: Shows "Node Network DevTools" by default
|
|
131
|
-
- **Fast Launch**: Opens in under 3 seconds
|
|
85
|
+
Once started, a minimal browser window will automatically open showing the real-time request list.
|
|
132
86
|
|
|
133
|
-
|
|
87
|
+
- **Compact size** (800x600) for side-by-side debugging.
|
|
88
|
+
- **Search & Filter** by URL, method, or status.
|
|
89
|
+
- **Details Panel** for headers, payload, and response.
|
|
90
|
+
- **Dark/Light** theme support.
|
|
134
91
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
- π **Details Panel** - View headers, payload, response, and timing
|
|
138
|
-
- π¨ **Theme Toggle** - Dark/Light theme support
|
|
139
|
-
- βΈοΈ **Pause/Resume** - Pause request capture for analysis
|
|
140
|
-
- π **Real-time Updates** - WebSocket-based live updates
|
|
92
|
+
If you need to access it manually, check the console output for the URL:
|
|
93
|
+
`π Node Network DevTools GUI started at http://localhost:9229`
|
|
141
94
|
|
|
142
95
|
### GUI Configuration
|
|
143
96
|
|
|
144
97
|
```bash
|
|
145
98
|
# Customize window size
|
|
146
|
-
NND_BROWSER_WIDTH=1024 NND_BROWSER_HEIGHT=768
|
|
99
|
+
NND_BROWSER_WIDTH=1024 NND_BROWSER_HEIGHT=768 node --import @mt0926/node-network-devtools/register your-script.js
|
|
147
100
|
|
|
148
101
|
# Customize window title
|
|
149
|
-
NND_BROWSER_TITLE="My App Network Monitor"
|
|
102
|
+
NND_BROWSER_TITLE="My App Network Monitor" node --import @mt0926/node-network-devtools/register your-script.js
|
|
150
103
|
|
|
151
104
|
# Specify GUI port
|
|
152
|
-
NND_GUI_PORT=9230
|
|
105
|
+
NND_GUI_PORT=9230 node --import @mt0926/node-network-devtools/register your-script.js
|
|
153
106
|
|
|
154
107
|
# Specify WebSocket port
|
|
155
|
-
NND_WS_PORT=9231
|
|
108
|
+
NND_WS_PORT=9231 node --import @mt0926/node-network-devtools/register your-script.js
|
|
156
109
|
|
|
157
110
|
# Disable GUI
|
|
158
|
-
NND_GUI_ENABLED=false
|
|
111
|
+
NND_GUI_ENABLED=false node --import @mt0926/node-network-devtools/register your-script.js
|
|
159
112
|
|
|
160
113
|
# Disable auto-open browser
|
|
161
|
-
NND_AUTO_OPEN=false
|
|
114
|
+
NND_AUTO_OPEN=false node --import @mt0926/node-network-devtools/register your-script.js
|
|
162
115
|
```
|
|
163
116
|
|
|
164
117
|
## π§ Configuration
|
|
@@ -190,7 +143,7 @@ NND_AUTO_OPEN=false npx nnd your-script.js
|
|
|
190
143
|
### Programmatic Configuration
|
|
191
144
|
|
|
192
145
|
```typescript
|
|
193
|
-
import { setConfig } from 'node-network-devtools';
|
|
146
|
+
import { setConfig } from '@mt0926/node-network-devtools';
|
|
194
147
|
|
|
195
148
|
setConfig({
|
|
196
149
|
maxRequests: 500,
|
|
@@ -210,7 +163,7 @@ setConfig({
|
|
|
210
163
|
```typescript
|
|
211
164
|
// Conditional installation based on environment
|
|
212
165
|
if (process.env.NODE_ENV === 'development') {
|
|
213
|
-
const { install } = await import('node-network-devtools');
|
|
166
|
+
const { install } = await import('@mt0926/node-network-devtools');
|
|
214
167
|
await install();
|
|
215
168
|
}
|
|
216
169
|
```
|
|
@@ -257,9 +210,10 @@ Or configure in `package.json`:
|
|
|
257
210
|
|
|
258
211
|
### Express
|
|
259
212
|
|
|
213
|
+
**ESM:**
|
|
260
214
|
```typescript
|
|
261
215
|
import express from 'express';
|
|
262
|
-
import { install } from 'node-network-devtools';
|
|
216
|
+
import { install } from '@mt0926/node-network-devtools';
|
|
263
217
|
|
|
264
218
|
await install();
|
|
265
219
|
|
|
@@ -267,33 +221,103 @@ const app = express();
|
|
|
267
221
|
// Your routes...
|
|
268
222
|
```
|
|
269
223
|
|
|
224
|
+
**CommonJS:**
|
|
225
|
+
```javascript
|
|
226
|
+
const express = require('express');
|
|
227
|
+
const { install } = require('@mt0926/node-network-devtools');
|
|
228
|
+
|
|
229
|
+
(async () => {
|
|
230
|
+
await install();
|
|
231
|
+
|
|
232
|
+
const app = express();
|
|
233
|
+
// Your routes...
|
|
234
|
+
})();
|
|
235
|
+
```
|
|
236
|
+
|
|
270
237
|
### Other Frameworks
|
|
271
238
|
|
|
272
239
|
Works with any Node.js framework! Just install the interceptor before your application code.
|
|
273
240
|
|
|
241
|
+
## π¦ Module System Support
|
|
242
|
+
|
|
243
|
+
This package supports both **ESM (ECMAScript Modules)** and **CommonJS** module systems, making it compatible with all Node.js projects.
|
|
244
|
+
|
|
245
|
+
### ESM (ECMAScript Modules)
|
|
246
|
+
|
|
247
|
+
Use `import` statements in projects with `"type": "module"` in package.json or `.mjs` files:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { install, getRequestStore } from '@mt0926/node-network-devtools';
|
|
251
|
+
import '@mt0926/node-network-devtools/register';
|
|
252
|
+
|
|
253
|
+
await install();
|
|
254
|
+
const store = getRequestStore();
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### CommonJS
|
|
258
|
+
|
|
259
|
+
Use `require()` statements in traditional Node.js projects or `.cjs` files:
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
const { install, getRequestStore } = require('@mt0926/node-network-devtools');
|
|
263
|
+
require('@mt0926/node-network-devtools/register');
|
|
264
|
+
|
|
265
|
+
(async () => {
|
|
266
|
+
await install();
|
|
267
|
+
const store = getRequestStore();
|
|
268
|
+
})();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### TypeScript
|
|
272
|
+
|
|
273
|
+
Full TypeScript support with type definitions for both module systems:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import type { Config, IRequestStore } from '@mt0926/node-network-devtools';
|
|
277
|
+
import { install, getRequestStore } from '@mt0926/node-network-devtools';
|
|
278
|
+
|
|
279
|
+
const config: Config = {
|
|
280
|
+
maxRequests: 500,
|
|
281
|
+
guiEnabled: true,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
await install();
|
|
285
|
+
const store: IRequestStore = getRequestStore();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Module Resolution
|
|
289
|
+
|
|
290
|
+
The package uses Node.js [Conditional Exports](https://nodejs.org/api/packages.html#conditional-exports) to automatically provide the correct module format:
|
|
291
|
+
|
|
292
|
+
- **ESM projects**: Resolves to `dist/esm/index.js`
|
|
293
|
+
- **CommonJS projects**: Resolves to `dist/cjs/index.js`
|
|
294
|
+
- **TypeScript**: Uses `dist/types/index.d.ts` for both
|
|
295
|
+
|
|
296
|
+
No configuration needed - it just works! π
|
|
297
|
+
|
|
274
298
|
## π API Reference
|
|
275
299
|
|
|
276
300
|
### Main Exports
|
|
277
301
|
|
|
278
302
|
```typescript
|
|
279
303
|
// Quick install
|
|
280
|
-
import { install, startGUI, stopGUI } from 'node-network-devtools';
|
|
304
|
+
import { install, startGUI, stopGUI } from '@mt0926/node-network-devtools';
|
|
281
305
|
|
|
282
306
|
// Configuration
|
|
283
|
-
import { getConfig, setConfig, resetConfig } from 'node-network-devtools';
|
|
307
|
+
import { getConfig, setConfig, resetConfig } from '@mt0926/node-network-devtools';
|
|
284
308
|
|
|
285
309
|
// Request store
|
|
286
|
-
import { getRequestStore } from 'node-network-devtools';
|
|
310
|
+
import { getRequestStore } from '@mt0926/node-network-devtools';
|
|
287
311
|
|
|
288
312
|
// Context tracing
|
|
289
313
|
import {
|
|
290
314
|
runWithTrace,
|
|
291
315
|
getCurrentTraceId,
|
|
292
316
|
generateTraceId
|
|
293
|
-
} from 'node-network-devtools';
|
|
317
|
+
} from '@mt0926/node-network-devtools';
|
|
294
318
|
|
|
295
319
|
// Interceptors
|
|
296
|
-
import { HttpPatcher, UndiciPatcher } from 'node-network-devtools';
|
|
320
|
+
import { HttpPatcher, UndiciPatcher } from '@mt0926/node-network-devtools';
|
|
297
321
|
```
|
|
298
322
|
|
|
299
323
|
### Request Tracing
|
|
@@ -301,7 +325,7 @@ import { HttpPatcher, UndiciPatcher } from 'node-network-devtools';
|
|
|
301
325
|
Correlate multiple requests in the same business flow:
|
|
302
326
|
|
|
303
327
|
```typescript
|
|
304
|
-
import { runWithTrace, getRequestStore } from 'node-network-devtools';
|
|
328
|
+
import { runWithTrace, getRequestStore } from '@mt0926/node-network-devtools';
|
|
305
329
|
|
|
306
330
|
await runWithTrace('user-login', async () => {
|
|
307
331
|
// These requests will be correlated with the same traceId
|
|
@@ -320,6 +344,7 @@ Check the [examples](./examples) directory for more usage examples:
|
|
|
320
344
|
|
|
321
345
|
- [basic-http](./examples/basic-http) - Basic HTTP request monitoring
|
|
322
346
|
- [fetch-api](./examples/fetch-api) - Fetch API monitoring
|
|
347
|
+
- [commonjs-usage](./examples/commonjs-usage) - CommonJS module usage
|
|
323
348
|
- [request-tracing](./examples/request-tracing) - Request tracing
|
|
324
349
|
- [express-server](./examples/express-server) - Express server example
|
|
325
350
|
- [programmatic-api](./examples/programmatic-api) - Programmatic API usage
|
|
@@ -331,7 +356,7 @@ Check the [examples](./examples) directory for more usage examples:
|
|
|
331
356
|
2. **Undici Interception**: Uses `Agent.compose()` to register interceptors for fetch requests
|
|
332
357
|
3. **Context Propagation**: Uses `AsyncLocalStorage` to pass TraceID through async call chains
|
|
333
358
|
4. **Event Bridge**: Forwards intercepted requests to WebSocket clients for real-time GUI updates
|
|
334
|
-
5. **
|
|
359
|
+
5. **Native Browser Launch**: Detects and launches your system's browser (Chrome/Edge/Chromium) in a dedicated app-mode window.
|
|
335
360
|
|
|
336
361
|
## π€ Contributing
|
|
337
362
|
|
|
@@ -369,7 +394,7 @@ MIT Β© [ddddd](https://github.com/dong0926)
|
|
|
369
394
|
|
|
370
395
|
- π [Report Issues](https://github.com/dong0926/node-network-devtools/issues)
|
|
371
396
|
- π¬ [Discussions](https://github.com/dong0926/node-network-devtools/discussions)
|
|
372
|
-
- π§ Email:
|
|
397
|
+
- π§ Email: xx630133368@gmail.com
|
|
373
398
|
|
|
374
399
|
---
|
|
375
400
|
|