@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.
Files changed (56) hide show
  1. package/README.md +134 -109
  2. package/README.zh-CN.md +62 -108
  3. package/dist/cjs/adapters/axios.js +2 -0
  4. package/dist/cjs/adapters/axios.js.map +1 -0
  5. package/dist/cjs/adapters/nextjs.js +133 -0
  6. package/dist/cjs/adapters/nextjs.js.map +1 -0
  7. package/dist/cjs/config.js +150 -0
  8. package/dist/cjs/config.js.map +1 -0
  9. package/dist/cjs/context/context-manager.js +139 -0
  10. package/dist/cjs/context/context-manager.js.map +1 -0
  11. package/dist/cjs/gui/browser-detector.js +263 -0
  12. package/dist/cjs/gui/browser-detector.js.map +1 -0
  13. package/dist/cjs/gui/browser-launcher.js +365 -0
  14. package/dist/cjs/gui/browser-launcher.js.map +1 -0
  15. package/dist/cjs/gui/event-bridge.js +197 -0
  16. package/dist/cjs/gui/event-bridge.js.map +1 -0
  17. package/dist/cjs/gui/port-utils.js +85 -0
  18. package/dist/cjs/gui/port-utils.js.map +1 -0
  19. package/dist/cjs/gui/server.js +267 -0
  20. package/dist/cjs/gui/server.js.map +1 -0
  21. package/dist/cjs/gui/websocket-hub.js +336 -0
  22. package/dist/cjs/gui/websocket-hub.js.map +1 -0
  23. package/dist/cjs/index.js +170 -0
  24. package/dist/cjs/index.js.map +1 -0
  25. package/dist/cjs/interceptors/http-patcher.js +275 -0
  26. package/dist/cjs/interceptors/http-patcher.js.map +1 -0
  27. package/dist/cjs/interceptors/undici-patcher.js +362 -0
  28. package/dist/cjs/interceptors/undici-patcher.js.map +1 -0
  29. package/dist/cjs/package.json +3 -0
  30. package/dist/cjs/register.js +95 -0
  31. package/dist/cjs/register.js.map +1 -0
  32. package/dist/cjs/store/ring-buffer.js +241 -0
  33. package/dist/cjs/store/ring-buffer.js.map +1 -0
  34. package/dist/cjs/test-setup.js +8 -0
  35. package/dist/cjs/test-setup.js.map +1 -0
  36. package/dist/cjs/utils/module-compat.js +83 -0
  37. package/dist/cjs/utils/module-compat.js.map +1 -0
  38. package/dist/esm/gui/server.js +41 -6
  39. package/dist/esm/gui/server.js.map +1 -1
  40. package/dist/esm/index.js +1 -1
  41. package/dist/esm/interceptors/undici-patcher.js +9 -4
  42. package/dist/esm/interceptors/undici-patcher.js.map +1 -1
  43. package/dist/esm/utils/module-compat.js +78 -0
  44. package/dist/esm/utils/module-compat.js.map +1 -0
  45. package/dist/gui/assets/index.css +1 -1
  46. package/dist/gui/assets/index.js +10 -10
  47. package/dist/types/gui/server.d.ts.map +1 -1
  48. package/dist/types/index.d.ts +1 -1
  49. package/dist/types/interceptors/undici-patcher.d.ts.map +1 -1
  50. package/dist/types/utils/module-compat.d.ts +34 -0
  51. package/dist/types/utils/module-compat.d.ts.map +1 -0
  52. package/package.json +42 -35
  53. package/dist/esm/cli.js +0 -203
  54. package/dist/esm/cli.js.map +0 -1
  55. package/dist/types/cli.d.ts +0 -8
  56. 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
- **Monitor Node.js network requests with Chrome DevTools integration and built-in Web GUI**
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
- [![npm version](https://img.shields.io/npm/v/node-network-devtools.svg)](https://www.npmjs.com/package/@mt0926/node-network-devtools)
8
+ [![npm version](https://img.shields.io/npm/v/@mt0926/node-network-devtools.svg)](https://www.npmjs.com/package/@mt0926/node-network-devtools)
8
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
- [![Node.js Version](https://img.shields.io/node/v/node-network-devtools.svg)](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
- ## ⚠️ Development Tool Only
17
+ ## πŸš€ Why Node Network DevTools?
18
18
 
19
- **This tool is designed for development environments only. Do NOT use in production!**
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
- - πŸ” **Dual Interception** - Supports both `http/https` modules and `undici/fetch` API
45
- - 🎯 **Zero Intrusion** - Auto-inject via `-r` or `--import`, no code changes needed
46
- - πŸ–₯️ **Minimal Browser Window** - Puppeteer-powered compact GUI window (800x600)
47
- - πŸ“Š **Built-in Web GUI** - Chrome DevTools-like interface with real-time updates
48
- - πŸ”— **Request Tracing** - AsyncLocalStorage-based request correlation
49
- - πŸ›‘οΈ **Security** - Auto-redact sensitive headers (Authorization, Cookie, etc.)
50
- - ⚑ **Next.js Compatible** - Preserves `next.revalidate`, `next.tags` options
51
- - πŸ“¦ **TypeScript** - Full TypeScript support with type definitions
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
  ![Web GUI](https://via.placeholder.com/800x450?text=Web+GUI+Screenshot)
57
36
 
58
- ### Chrome DevTools Integration
59
- ![Chrome DevTools](https://via.placeholder.com/800x450?text=Chrome+DevTools+Screenshot)
60
-
61
37
  ## πŸš€ Quick Start
62
38
 
63
- ### Installation
39
+ ### 1. Installation
64
40
 
65
41
  ```bash
66
- npm install node-network-devtools puppeteer
42
+ npm install @mt0926/node-network-devtools
67
43
  # or
68
- pnpm add node-network-devtools puppeteer
69
- # or
70
- yarn add node-network-devtools puppeteer
44
+ pnpm add @mt0926/node-network-devtools
71
45
  ```
72
46
 
73
- **Note**: Puppeteer is required for the GUI browser window. If not installed, you'll see a friendly error message with installation instructions.
74
-
75
- ### Usage
47
+ > **Note**: No extra dependencies like Puppeteer are required! It uses your system's existing browser.
76
48
 
77
- #### Method 1: CLI (Recommended)
49
+ ### 2. Usage (Recommended)
78
50
 
79
- ```bash
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
- The CLI automatically injects the interceptor and opens the GUI.
86
-
87
- #### Method 2: Using `-r` flag
53
+ **ESM:**
54
+ ```typescript
55
+ import { install } from '@mt0926/node-network-devtools';
88
56
 
89
- ```bash
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
- #### Method 3: Programmatic
94
-
95
- ```typescript
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
- // Your application code
101
- import express from 'express';
102
- const app = express();
103
- // ...
64
+ (async () => {
65
+ await install();
66
+ })();
104
67
  ```
105
68
 
106
- ### Viewing Requests
107
-
108
- After starting your application:
69
+ ### 3. Advanced: Zero-Code Injection
109
70
 
110
- - **Web GUI** (Default): A minimal browser window will automatically open showing the GUI
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
- To manually access the GUI, look for the URL in the console output:
73
+ **ESM:**
74
+ ```bash
75
+ node --import @mt0926/node-network-devtools/register your-script.js
116
76
  ```
117
- πŸš€ Node Network DevTools GUI started at http://localhost:9229
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
- The built-in Web GUI provides a Chrome DevTools-like experience for monitoring network requests.
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
- ### Features
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
- - πŸ“‹ **Request List** - Real-time display of all network requests
136
- - πŸ” **Search & Filter** - Filter by URL, method, status code, and type
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 npx nnd your-script.js
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" npx nnd your-script.js
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 npx nnd your-script.js
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 npx nnd your-script.js
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 npx nnd your-script.js
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 npx nnd your-script.js
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. **Minimal Browser**: Uses Puppeteer to launch a compact browser window in app mode
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: your.email@example.com
397
+ - πŸ“§ Email: xx630133368@gmail.com
373
398
 
374
399
  ---
375
400