nodewise 1.0.0
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/LICENSE +21 -0
- package/README.md +97 -0
- package/USER_MANUAL.md +106 -0
- package/bin/nodewise.js +166 -0
- package/examples/express-server.js +70 -0
- package/examples/express-with-errors.js +63 -0
- package/examples/module-not-found.js +9 -0
- package/examples/reference-error.js +9 -0
- package/examples/syntax-error.js +11 -0
- package/examples/type-error.js +10 -0
- package/examples/working-app.js +35 -0
- package/package.json +49 -0
- package/src/config.js +167 -0
- package/src/errorPatterns.js +3253 -0
- package/src/errorWrapper.js +43 -0
- package/src/explainer/gemini.js +212 -0
- package/src/explainer/index.js +51 -0
- package/src/explainer/interactive.js +123 -0
- package/src/explainer/normal.js +27 -0
- package/src/expressErrorHandler.js +68 -0
- package/src/index.js +14 -0
- package/src/runner.js +243 -0
- package/src/setup.js +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gourab Das
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# nodewise
|
|
2
|
+
|
|
3
|
+
> Node.js error explainer with AI-powered clarity
|
|
4
|
+
|
|
5
|
+
A production-ready CLI dev tool that intercepts and explains runtime errors in your Node.js applications. It works like nodemon but instead of just restarting on crash, it explains what went wrong in simple, natural language.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## šØāš» Developer Information
|
|
10
|
+
|
|
11
|
+
**Gourab Das**
|
|
12
|
+
- **Email:** [dgourab574@gmail.com](mailto:dgourab574@gmail.com) | [gourab.sde@gmail.com](mailto:gourab.sde@gmail.com)
|
|
13
|
+
- **LinkedIn:** [linkedin.com/in/gourab2005](https://www.linkedin.com/in/gourab2005/)
|
|
14
|
+
- **GitHub:** [github.com/Gourab2005](https://github.com/Gourab2005)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## š How to Use
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
Install `nodewise` as a development dependency in your project:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -D nodewise
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or run it directly using `npx`:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx nodewise your-app.js
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Usage
|
|
35
|
+
|
|
36
|
+
1. **First-time Experience**: The first time you run it, you'll be prompted to choose between **Gemini AI** and **Normal Detection** mode.
|
|
37
|
+
2. **Running Scripts**: Simply replace `node` or `nodemon` with `nodewise`:
|
|
38
|
+
```bash
|
|
39
|
+
npx nodewise server.js
|
|
40
|
+
```
|
|
41
|
+
3. **Arguments**: Pass your app arguments as usual:
|
|
42
|
+
```bash
|
|
43
|
+
npx nodewise server.js --port 3000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## š¤ Why use nodewise?
|
|
49
|
+
|
|
50
|
+
Traditional error messages can be cryptic, long, or stacked with irrelevant internal module traces. **nodewise** solves this by:
|
|
51
|
+
|
|
52
|
+
- **Saving Time**: No more Googling stack traces. Get the fix instantly.
|
|
53
|
+
- **Smart Context**: Unlike manual searching, the AI mode understands your specific code structure.
|
|
54
|
+
- **Seamless Flow**: It combines the best of `nodemon` (auto-restart) with a built-in "senior developer" who explains your mistakes.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## ⨠Features
|
|
59
|
+
|
|
60
|
+
- š¤ **Gemini Explainer**: Deep AI-powered analysis of crashes with code-specific solutions.
|
|
61
|
+
- š **Normal Detection**: Pattern-based error detection for 50+ common Node.js errors (offline).
|
|
62
|
+
- š **Auto-Restart**: Watches `.js` and `.json` files and restarts instantly on save.
|
|
63
|
+
- š **Minimalist Design**: High-end, gapped terminal output that doesn't clutter your workspace.
|
|
64
|
+
- ā” **Lightweight**: Zero heavy dependencies, keeping your dev environment fast.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## š Example Output
|
|
69
|
+
|
|
70
|
+
⦠GEMINI INTELLIGENCE
|
|
71
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
72
|
+
|
|
73
|
+
Summary: This error occurs when you try to import or require a file that doesn't exist.
|
|
74
|
+
|
|
75
|
+
Cause: Typo in the file name or path, or the file was moved/deleted.
|
|
76
|
+
|
|
77
|
+
File: src/app.js:12
|
|
78
|
+
|
|
79
|
+
Fix:
|
|
80
|
+
1. Check the spelling of the file path.
|
|
81
|
+
2. Verify the file exists in that location.
|
|
82
|
+
3. Use an absolute path if needed: `path.join(__dirname, './config')`
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## CLI Commands
|
|
87
|
+
|
|
88
|
+
| Command | Description |
|
|
89
|
+
| :--- | :--- |
|
|
90
|
+
| `nodewise --setup` | Change modes or update AI configuration. |
|
|
91
|
+
| `nodewise --reset` | Reset all configurations. |
|
|
92
|
+
| `nodewise --help` | Show usage manual. |
|
|
93
|
+
| `nodewise -v` | Show current version. |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
Made with ā¤ļø by [Gourab Das](https://github.com/Gourab2005)
|
package/USER_MANUAL.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# š NodeWise User Manual
|
|
2
|
+
|
|
3
|
+
Welcome to **NodeWise**, your AI-powered companion for Node.js development. This manual will help you get the most out of NodeWise's error explanation and auto-restart features.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## š Getting Started
|
|
8
|
+
|
|
9
|
+
NodeWise is designed to be a drop-in replacement for `node` or `nodemon` during development.
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
If you haven't already, you can link it globally or install it in your project:
|
|
13
|
+
```bash
|
|
14
|
+
# Link for local development
|
|
15
|
+
npm link
|
|
16
|
+
|
|
17
|
+
# Install as a dev dependency
|
|
18
|
+
npm install -D nodewise
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Initial Setup
|
|
22
|
+
The first time you run NodeWise, it will launch a setup wizard to configure your preferred explanation mode.
|
|
23
|
+
```bash
|
|
24
|
+
npx nodewise --setup
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## š¤ Explanation Modes
|
|
30
|
+
|
|
31
|
+
### 1. Gemini Explainer (AI-Powered)
|
|
32
|
+
The "Top-G" mode. It uses Google's latest Gemini models to analyze your specific code and provide context-aware fixes.
|
|
33
|
+
|
|
34
|
+
* **Setup**: Requires a free Gemini API Key from [Google AI Studio](https://aistudio.google.com/app/apikey).
|
|
35
|
+
* **Best for**: Complex logic errors, obscure Node.js core errors, and step-by-step fix guides.
|
|
36
|
+
* **Features**: Beautiful minimalist terminal output with neon highlighting.
|
|
37
|
+
|
|
38
|
+
### 2. Normal Detection (Offline)
|
|
39
|
+
A lightning-fast, pattern-based mode that works entirely offline.
|
|
40
|
+
|
|
41
|
+
* **Setup**: No setup required.
|
|
42
|
+
* **Best for**: Common errors like `MODULE_NOT_FOUND`, `TypeError`, and `ReferenceError`.
|
|
43
|
+
* **Features**: Zero latency, works without an internet connection.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## āØļø Command Line Interface
|
|
48
|
+
|
|
49
|
+
| Command | Description |
|
|
50
|
+
| :--- | :--- |
|
|
51
|
+
| `nodewise <script.js>` | Run a script with auto-restart and error explainer. |
|
|
52
|
+
| `nodewise --setup` | Change modes or update your Gemini API key. |
|
|
53
|
+
| `nodewise --reset` | Wipe configuration and start fresh. |
|
|
54
|
+
| `nodewise --help` | Show available options and examples. |
|
|
55
|
+
| `nodewise -v` | Check your current NodeWise version. |
|
|
56
|
+
|
|
57
|
+
### Running with Arguments
|
|
58
|
+
You can pass arguments to your script just like you would with node:
|
|
59
|
+
```bash
|
|
60
|
+
nodewise server.js --port 3000 --env production
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## āļø Configuration
|
|
66
|
+
NodeWise saves your preferences in `nodewise.config.json` in your project root.
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mode": "gemini",
|
|
71
|
+
"gemini": {
|
|
72
|
+
"apiKey": "YOUR_KEY_HERE"
|
|
73
|
+
},
|
|
74
|
+
"autoRestart": true,
|
|
75
|
+
"ignorePatterns": ["node_modules", ".git"],
|
|
76
|
+
"timeout": 60000
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
* **autoRestart**: Set to `false` if you don't want the process to restart on file changes.
|
|
81
|
+
* **timeout**: Increase this if the AI is taking too long to respond on slow connections.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## ⨠Pro Tips
|
|
86
|
+
|
|
87
|
+
### 1. Minimalist AI Insight
|
|
88
|
+
When a crash occurs in Gemini mode, you'll see a clean, gapped output. We've removed bulky boxes to keep your terminal clean. Look for the **⦠GEMINI INTELLIGENCE** header.
|
|
89
|
+
|
|
90
|
+
### 2. Auto-Restart
|
|
91
|
+
NodeWise watches your `.js` and `.json` files. As soon as you save a fix, NodeWise will instantly restart your application, allowing for a rapid "Code-Crash-Fix-Repeat" cycle.
|
|
92
|
+
|
|
93
|
+
### 3. Graceful Exit
|
|
94
|
+
Use `Ctrl+C` to shut down both your application and the NodeWise watcher gracefully.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## š Troubleshooting
|
|
99
|
+
|
|
100
|
+
* **API Timeouts**: If you see "Gemini timed out," check your internet connection or increase the `timeout` in `nodewise.config.json`.
|
|
101
|
+
* **Invalid Key**: Ensure your API key is correct by re-running `nodewise --setup`.
|
|
102
|
+
* **Files not watching**: Ensure the directory you are working in doesn't have an ignore pattern matching your files.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
*Made with ā¤ļø for Node.js developers.*
|
package/bin/nodewise.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* bin/nodewise.js
|
|
5
|
+
*
|
|
6
|
+
* CLI entry point
|
|
7
|
+
* Handles command-line arguments and orchestrates the setup/run flow
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const config = require('../src/config');
|
|
13
|
+
const { runSetup } = require('../src/setup');
|
|
14
|
+
const { Runner } = require('../src/runner');
|
|
15
|
+
|
|
16
|
+
const VERSION = '1.0.0';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse command line arguments
|
|
20
|
+
*/
|
|
21
|
+
function parseArgs() {
|
|
22
|
+
const args = process.argv.slice(2);
|
|
23
|
+
const flags = {
|
|
24
|
+
help: false,
|
|
25
|
+
version: false,
|
|
26
|
+
setup: false,
|
|
27
|
+
reset: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let scriptPath = null;
|
|
31
|
+
const scriptArgs = [];
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < args.length; i++) {
|
|
34
|
+
const arg = args[i];
|
|
35
|
+
|
|
36
|
+
if (arg === '--help' || arg === '-h') {
|
|
37
|
+
flags.help = true;
|
|
38
|
+
} else if (arg === '--version' || arg === '-v') {
|
|
39
|
+
flags.version = true;
|
|
40
|
+
} else if (arg === '--setup') {
|
|
41
|
+
flags.setup = true;
|
|
42
|
+
} else if (arg === '--reset') {
|
|
43
|
+
flags.reset = true;
|
|
44
|
+
} else if (!scriptPath) {
|
|
45
|
+
scriptPath = arg;
|
|
46
|
+
} else {
|
|
47
|
+
scriptArgs.push(arg);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { flags, scriptPath, scriptArgs };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Display help message
|
|
56
|
+
*/
|
|
57
|
+
function showHelp() {
|
|
58
|
+
console.log(`
|
|
59
|
+
${chalk.cyan.bold('nodewise ' + VERSION)} ${chalk.gray('- Node.js error explainer with AI-powered clarity')}
|
|
60
|
+
|
|
61
|
+
${chalk.bold('USAGE')}
|
|
62
|
+
npx nodewise [options] <script> [script-args]
|
|
63
|
+
|
|
64
|
+
${chalk.bold('OPTIONS')}
|
|
65
|
+
-h, --help Show this help message
|
|
66
|
+
-v, --version Show version
|
|
67
|
+
--setup Run setup wizard
|
|
68
|
+
--reset Reset configuration
|
|
69
|
+
|
|
70
|
+
${chalk.bold('EXAMPLES')}
|
|
71
|
+
npx nodewise app.js
|
|
72
|
+
npx nodewise server.js --port 3000
|
|
73
|
+
npx nodewise --setup (configure explanation mode)
|
|
74
|
+
npx nodewise --reset (reset configuration)
|
|
75
|
+
|
|
76
|
+
${chalk.bold('MODES')}
|
|
77
|
+
${chalk.cyan('Gemini Explainer')} - AI-powered error explanations using Google Gemini
|
|
78
|
+
${chalk.cyan('Normal Detection')} - Pattern-based error detection (offline)
|
|
79
|
+
|
|
80
|
+
${chalk.bold('CONFIGURATION')}
|
|
81
|
+
Settings are saved in ${chalk.yellow('nodewise.config.json')} in your project root.
|
|
82
|
+
|
|
83
|
+
${chalk.bold('DOCUMENTATION')}
|
|
84
|
+
https://github.com/yourusername/nodewise
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Display version
|
|
90
|
+
*/
|
|
91
|
+
function showVersion() {
|
|
92
|
+
console.log(`nodewise ${VERSION}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Main CLI function
|
|
97
|
+
*/
|
|
98
|
+
async function main() {
|
|
99
|
+
const { flags, scriptPath, scriptArgs } = parseArgs();
|
|
100
|
+
|
|
101
|
+
// Handle info flags
|
|
102
|
+
if (flags.help) {
|
|
103
|
+
showHelp();
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (flags.version) {
|
|
108
|
+
showVersion();
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Handle setup flow
|
|
113
|
+
if (flags.setup || flags.reset) {
|
|
114
|
+
try {
|
|
115
|
+
await runSetup();
|
|
116
|
+
process.exit(0);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(chalk.red('Setup failed:'), error.message);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Check if script path is provided
|
|
124
|
+
if (!scriptPath) {
|
|
125
|
+
console.error(chalk.red('Error: Please provide a script to run\n'));
|
|
126
|
+
showHelp();
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Resolve script path
|
|
131
|
+
const resolvedScriptPath = path.resolve(process.cwd(), scriptPath);
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
// Load or create configuration
|
|
135
|
+
let appConfig = config.loadConfig();
|
|
136
|
+
|
|
137
|
+
if (!appConfig) {
|
|
138
|
+
console.log(chalk.cyan('No configuration found. Running setup wizard...\n'));
|
|
139
|
+
appConfig = await runSetup();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Start the runner
|
|
143
|
+
const runner = new Runner(resolvedScriptPath, scriptArgs, appConfig);
|
|
144
|
+
|
|
145
|
+
// Handle graceful shutdown
|
|
146
|
+
process.on('SIGINT', () => {
|
|
147
|
+
runner.handleShutdown();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
process.on('SIGTERM', () => {
|
|
151
|
+
runner.handleShutdown();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Start running
|
|
155
|
+
runner.start();
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error(chalk.red('Fatal error:'), error.message);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Run the CLI
|
|
163
|
+
main().catch((error) => {
|
|
164
|
+
console.error(chalk.red('Unexpected error:'), error);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// examples/express-server.js
|
|
2
|
+
// Express app with integrated nodewise error handling
|
|
3
|
+
// This shows the correct way to set up Express for error explanation
|
|
4
|
+
|
|
5
|
+
const express = require('express');
|
|
6
|
+
const { nodewiseErrorHandler, asyncHandler } = require('../src/expressErrorHandler');
|
|
7
|
+
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
app.use(express.json());
|
|
11
|
+
|
|
12
|
+
// =========== ROUTES ===========
|
|
13
|
+
|
|
14
|
+
// Route 1: Intentional TypeError
|
|
15
|
+
app.get('/error1', (req, res) => {
|
|
16
|
+
const obj = null;
|
|
17
|
+
obj.kjbvend("Hello"); // TypeError: obj.kjbvend is not a function
|
|
18
|
+
res.send('This will not run');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Route 2: Intentional ReferenceError
|
|
22
|
+
app.get('/error2', (req, res) => {
|
|
23
|
+
console.log(undefinedVar); // ReferenceError
|
|
24
|
+
res.send('This will not run');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Route 3: JSON parsing error
|
|
28
|
+
app.get('/error3', (req, res) => {
|
|
29
|
+
const json = '{ invalid }';
|
|
30
|
+
JSON.parse(json); // SyntaxError
|
|
31
|
+
res.send('This will not run');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Route 4: Async error
|
|
35
|
+
app.get('/error4', asyncHandler(async (req, res) => {
|
|
36
|
+
// This will throw an error
|
|
37
|
+
throw new Error('Async operation failed');
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
// Route 5: Working route
|
|
41
|
+
app.get('/', (req, res) => {
|
|
42
|
+
res.json({
|
|
43
|
+
message: 'Express server with nodewise error handling',
|
|
44
|
+
routes: [
|
|
45
|
+
'GET / - this page',
|
|
46
|
+
'GET /error1 - TypeError (obj.kjbvend)',
|
|
47
|
+
'GET /error2 - ReferenceError (undefined variable)',
|
|
48
|
+
'GET /error3 - JSON SyntaxError',
|
|
49
|
+
'GET /error4 - Async error'
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// =========== ERROR HANDLER ===========
|
|
55
|
+
// THIS IS IMPORTANT: Add error handler middleware AFTER all routes
|
|
56
|
+
// This will catch all errors and log them to stderr where nodewise catches them
|
|
57
|
+
app.use(nodewiseErrorHandler);
|
|
58
|
+
|
|
59
|
+
// =========== START SERVER ===========
|
|
60
|
+
const PORT = process.env.PORT || 3000;
|
|
61
|
+
app.listen(PORT, () => {
|
|
62
|
+
console.log(`\nā Express server running at http://localhost:${PORT}`);
|
|
63
|
+
console.log('\nTry these URLs to trigger errors:');
|
|
64
|
+
console.log(` GET http://localhost:${PORT}/error1 (TypeError)`);
|
|
65
|
+
console.log(` GET http://localhost:${PORT}/error2 (ReferenceError)`);
|
|
66
|
+
console.log(` GET http://localhost:${PORT}/error3 (SyntaxError)`);
|
|
67
|
+
console.log(` GET http://localhost:${PORT}/error4 (Async Error)\n`);
|
|
68
|
+
console.log('Run nodewise to see errors explained:');
|
|
69
|
+
console.log(' nodewise examples/express-server.js\n');
|
|
70
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// examples/express-with-errors.js
|
|
2
|
+
// Node.js app with integrated error handling for nodewise
|
|
3
|
+
// This app demonstrates how runtime errors are caught and explained
|
|
4
|
+
|
|
5
|
+
const errorWrapper = require('../src/errorWrapper');
|
|
6
|
+
|
|
7
|
+
// Setup error handlers if running under nodewise
|
|
8
|
+
if (process.env.NODEWISE_ACTIVE) {
|
|
9
|
+
errorWrapper.setupErrorHandlers();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Simulate a server with runtime error handling
|
|
13
|
+
const http = require('http');
|
|
14
|
+
|
|
15
|
+
const server = http.createServer((req, res) => {
|
|
16
|
+
// Route 1: TypeError
|
|
17
|
+
if (req.url === '/error1') {
|
|
18
|
+
const obj = null;
|
|
19
|
+
obj.method(); // TypeError: Cannot read property 'method' of null
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Route 2: ReferenceError
|
|
24
|
+
if (req.url === '/error2') {
|
|
25
|
+
console.log(undefinedVariable); // ReferenceError
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Route 3: JSON parsing error
|
|
30
|
+
if (req.url === '/error3') {
|
|
31
|
+
const json = '{ invalid json }';
|
|
32
|
+
const parsed = JSON.parse(json); // SyntaxError
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Route 4: Working route
|
|
37
|
+
if (req.url === '/') {
|
|
38
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
39
|
+
res.end(JSON.stringify({
|
|
40
|
+
message: 'Node.js app running with nodewise error handling',
|
|
41
|
+
routes: [
|
|
42
|
+
'GET / - this page',
|
|
43
|
+
'GET /error1 - TypeError',
|
|
44
|
+
'GET /error2 - ReferenceError',
|
|
45
|
+
'GET /error3 - JSON SyntaxError'
|
|
46
|
+
]
|
|
47
|
+
}));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
res.writeHead(404);
|
|
52
|
+
res.end('Not Found');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const PORT = process.env.PORT || 3000;
|
|
56
|
+
server.listen(PORT, () => {
|
|
57
|
+
console.log(`\nā Server running at http://localhost:${PORT}`);
|
|
58
|
+
console.log('\nTry these URLs to trigger errors:');
|
|
59
|
+
console.log(` curl http://localhost:${PORT}/error1 (TypeError)`);
|
|
60
|
+
console.log(` curl http://localhost:${PORT}/error2 (ReferenceError)`);
|
|
61
|
+
console.log(` curl http://localhost:${PORT}/error3 (SyntaxError)\n`);
|
|
62
|
+
});
|
|
63
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// examples/module-not-found.js
|
|
2
|
+
// This file demonstrates a MODULE_NOT_FOUND error
|
|
3
|
+
|
|
4
|
+
console.log('Starting app...');
|
|
5
|
+
|
|
6
|
+
// Try to require a non-existent module
|
|
7
|
+
const nonExistent = require('./this-file-does-not-exist.js');
|
|
8
|
+
|
|
9
|
+
console.log('This will not run');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// examples/working-app.js
|
|
2
|
+
// A simple working Express server example
|
|
3
|
+
|
|
4
|
+
const http = require('http');
|
|
5
|
+
|
|
6
|
+
const PORT = process.env.PORT || 3000;
|
|
7
|
+
|
|
8
|
+
const server = http.createServer((req, res) => {
|
|
9
|
+
if (req.url === '/') {
|
|
10
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
11
|
+
res.end('Hello from nodewise!\n');
|
|
12
|
+
} else if (req.url === '/api/data') {
|
|
13
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
14
|
+
res.end(JSON.stringify({ message: 'Success', timestamp: new Date() }));
|
|
15
|
+
} else {
|
|
16
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
17
|
+
res.end('Not Found\n');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
server.listen(PORT, () => {
|
|
22
|
+
console.log(`\nā Server running at http://localhost:${PORT}`);
|
|
23
|
+
console.log(` Try: curl http://localhost:${PORT}`);
|
|
24
|
+
console.log(` Or: curl http://localhost:${PORT}/api/data\n`);
|
|
25
|
+
console.log('Edit this file to trigger a restart...\n');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Graceful shutdown
|
|
29
|
+
process.on('SIGTERM', () => {
|
|
30
|
+
console.log('\nShutting down...');
|
|
31
|
+
server.close(() => {
|
|
32
|
+
console.log('Server closed');
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nodewise",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node.js error explainer with AI-powered clarity",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"nodewise": "bin/nodewise.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cli",
|
|
15
|
+
"node",
|
|
16
|
+
"error",
|
|
17
|
+
"debugging",
|
|
18
|
+
"ai",
|
|
19
|
+
"gemini",
|
|
20
|
+
"explainer"
|
|
21
|
+
],
|
|
22
|
+
"author": "Gourab Das",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"inquirer": "^9.2.15",
|
|
26
|
+
"axios": "^1.6.5",
|
|
27
|
+
"chokidar": "^3.5.3",
|
|
28
|
+
"chalk": "^4.1.2"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin",
|
|
32
|
+
"src",
|
|
33
|
+
"examples",
|
|
34
|
+
"README.md",
|
|
35
|
+
"USER_MANUAL.md"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/Gourab2005/nodewise.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/Gourab2005/nodewise/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/Gourab2005/nodewise#readme",
|
|
45
|
+
"devDependencies": {},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|