friendly-errors
v1.0.4
Published
A Node.js utility for displaying clean, colorful, and helpful error messages with suggestions and highlighted code snippets.
Maintainers
Readme
write a single readme file containing everything
# friendly-errors
✨ Clean, colorful, and helpful error messages for Node.js — with suggestions, highlighted code snippets, and developer-friendly output.
---
## 📦 Install
npm install friendly-errors
---
## 🚀 Quick Usage
Require it at the start of your application to enable colorful, friendly error handling:
// index.js // Enable friendly errors require('friendly-errors');
// Example runtime error function greet(name) { return "Hello, " + name.toUpperCase(); }
greet(); // This will cause a TypeError
Run your app:
node index.js
---
## Example Output Preview
❌ TypeError: Cannot read property 'toUpperCase' of undefined at greet (/home/user/project/index.js:5:25)
3 | function greet(name) { 4 | return "Hello, " + name.toUpperCase();
5 | }
💡 Suggestion: Make sure you pass a string to 'greet' before calling .toUpperCase().
---
## 🛠 Features
- 🎯 Highlights the exact line of the error with a red background
- 📌 Shows 2 lines of context before & after the error
- 💡 Provides smart suggestions for common mistakes
- 🖌 Uses `chalk` for colorful, readable output
- ⚡ Hooks into `uncaughtException` and `unhandledRejection`
---
## 📚 API
Just require the module:
require('friendly-errors');
No configuration needed — it automatically improves your error output, working for both synchronous and asynchronous errors.
---
## 📄 License
MIT License
Copyright (c) 2025 Maurya Suryakant (npm: white-darkness)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---
## 🤝 Contributing
Pull requests, issues, and feature suggestions are welcome! Please fork the repository and create a PR with your changes.