Skip to content

sunnyghodeswar/node-express-crashless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ node-express-crashless

Minimal Express.js application demonstrating real-world crash prevention, async safety, and smart logging using Crashless.

Crashless ensures your app never crashes unexpectedly — even if async DB calls explode 💣, APIs fail 🌍, or developers “forget” try-catch 😅.


🚀 Quick Start

🧩 1. Install Dependencies

npm install

🧠 2. Run in Development Mode

npm run dev

✅ Shows full stack traces
✅ Logs every crash with metadata
✅ No message masking — useful for debugging

Example output:

⚡ Server running on http://localhost:4000
[Crashless] Error: Database read failed for user ID: 1

🛡️ 3. Run in Production Mode

npm start

✅ Sensitive messages masked
✅ Stack traces hidden
✅ Clean, production-friendly logs


🧪 4. Run Automated Tests

npm test

Runs all route tests using Mocha + Supertest
Verifies async, sync, and external API failures are gracefully handled.


🔗 Example Endpoints

Method Route Description
GET /ping Health check (returns OK)
GET /user/:id Simulates DB read failure
POST /user Simulates DB write failure
DELETE /user/:id Simulates DB delete failure
GET /external Simulates failed external API call
GET /crash Manual “organic” crash

🧰 Example Commands (from separate terminals)

Terminal 1 → Start the app

npm run dev

Terminal 2 → Hit routes

curl -s http://localhost:4000/user/1
curl -s -X POST http://localhost:4000/user -H "Content-Type: application/json" -d '{"name":"Sunny"}'
curl -s http://localhost:4000/crash
curl -s http://localhost:4000/external

Each response will return a standardized JSON structure like:

{
  "success": false,
  "message": "Database read failed for user ID: 1",
  "code": "SERVER_ERROR"
}

🧠 File Structure

node-express-crashless/
├── server.js        # Express + Crashless integration
├── db.js            # Simulated DB & API failure logic
├── package.json     # Scripts & deps
├── .gitignore       # Clean repo setup
└── README.md        # You’re reading this 😎

🧾 Example Logs

Development mode (npm run dev):

⚡ Server running on http://localhost:4000
[Crashless] Error: Database read failed for user ID: 1
{ method: 'GET', path: '/user/1', status: 500, timestamp: '...' }

Production mode (npm start):

⚡ Server running on http://localhost:4000
[Crashless] Error: Masked error (production mode)
{ method: 'GET', path: '/user/1', status: 500 }

🧠 Live Demo

👉 Try it instantly on StackBlitz:
https://stackblitz.com/github/sunnyghodeswar/node-express-crashless?file=server.js


🪄 Related Links


🧑‍💻 Author

Sunny Ghodeswar
Senior Full-Stack Developer — Pune, India 🇮🇳
Building Vegaa ⚡ & Crashless 🧯 for safer, faster backends.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published