nautanki-js-test
Version:
Filmy error handler for Node.js, Express, and Browser. Adds Bollywood-level drama to your crashes!
213 lines (148 loc) • 4.4 kB
Markdown
# Nautanki.js 🎠- Filmy Error Handler for Node.js, Express, and Browser
Add Bollywood drama to your application's errors! **Nautanki.js** makes debugging fun, colorful, and entertaining.
## Features
* **Node.js Error Handling** – Catch uncaught exceptions and unhandled promise rejections with flair.
* **Express.js Middleware** – Cinematic error responses for Express applications.
* **Browser Error Handling** – Bollywood-style messages in the browser console.
* **Customizable Messages** – Includes dialogues and meme-worthy lines.
* **Beautiful Error Display** – Colorful, well-formatted console messages.
## Installation
```bash
npm install nautanki-js
# or
yarn add nautanki-js
```
## Usage
### Node.js
```javascript
// Import named or default export
import { setupNodeHandler, disableNodeHandler } from 'nautanki-js';
// or
import setupNodeHandler from 'nautanki-js';
// Activate Nautanki
setupNodeHandler();
// Example: Throw an uncaught exception
// throw new Error("Node.js mein gadbad ho gayi!");
// Example: Unhandled promise rejection
// Promise.reject("Promise ne dhokha de diya!");
// To disable
// disableNodeHandler();
```
#### Test Node.js
`test.js`:
```javascript
import setupNodeHandler from 'nautanki-js';
setupNodeHandler();
console.log("About to throw an error...");
throw new Error("Network hi gayab ho gaya!");
```
Run:
```bash
node test.js
```
You’ll see colorful, Bollywood-style error messages in the console.
### Express.js
```javascript
import express from 'express';
import { nautankiExpressHandler } from 'nautanki-js';
const app = express();
// Route that throws an error
app.get('/', (req, res, next) => {
next(new Error("Express mein dhamaal! 🤯"));
});
// Route that works fine
app.get('/ok', (req, res) => {
res.send("Sab theek hai!");
});
// Async error example
app.get('/async', async (req, res, next) => {
try {
await new Promise((_, reject) => setTimeout(() => reject(new Error('Async error ho gaya!')), 100));
} catch (err) {
next(err);
}
});
// Use Nautanki middleware LAST
app.use(nautankiExpressHandler);
app.listen(3000, () => {
console.log("🚀 Server running at http://localhost:3000");
});
```
### Browser
Bundle Nautanki.js with Webpack, Rollup, or Parcel:
```javascript
import { setupBrowserHandler, disableBrowserHandler } from 'nautanki-js/handlers/browserHandler';
// Activate Nautanki for browser
setupBrowserHandler();
// Example errors
function causeError() {
throw new Error("Browser mein error aa gaya!");
}
function causePromiseError() {
Promise.reject(new Error("Browser promise ne bhi saath chhod diya!"));
}
// Disable handler if needed
// disableBrowserHandler();
```
#### Browser Demo HTML
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nautanki Browser Demo</title>
<script src="./dist/bundle.js" type="module" defer></script>
</head>
<body>
<h1>Nautanki.js Browser Demo</h1>
<p>Open the console to see the drama!</p>
<button onclick="causeError()">Trigger Error</button>
<button onclick="causePromiseError()">Trigger Promise Error</button>
</body>
</html>
```
## Testing Locally
### 1. npm link
```bash
# In nautanki-js folder
npm link
# In test project
npm link nautanki-js
```
### 2. Using tarball
```bash
npm pack
npm install /path/to/nautanki-js-1.0.1.tgz
```
### 3. Local folder reference
`package.json` in test project:
```json
{
"dependencies": {
"nautanki-js": "file:../path/to/nautanki-js"
}
}
```
## Troubleshooting
* **Banner not showing** – Ensure postinstall script and dependencies (`colorette`, `figlet`, `boxen`) are installed.
* **Handler not catching errors** – Make sure `setupNodeHandler()` or the correct setup function is called.
* **Express issues** – Middleware must be last in stack.
* **Browser issues** – Bundle properly and initialize before any errors occur.
## Contributing
Open issues, pull requests, or suggest new dialogues!
## License
MIT License. See `LICENSE` file.
## Author
**mainhoonsobu**
t me to do that?