Youch: Pretty Print JavaScript Errors

4.1.1 · active · verified Sun Apr 19

Youch is an error-parsing library designed to transform raw JavaScript error stack traces into highly readable and visually appealing output. It can render these errors into self-contained HTML pages for web contexts or formatted ANSI output for terminal environments. The current stable version is 4.1.1, with frequent updates, including beta releases for new features and bug fixes. A key differentiator is its ability to provide detailed error information, including code snippets, request/response metadata, and configurable links to code editors, significantly enhancing the developer experience compared to standard unformatted stack traces. It is widely adopted by frameworks like Hono, Nuxt, and AdonisJS, emphasizing its utility in modern web development workflows.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate Youch into a Node.js HTTP server to catch errors and render them as a rich, self-contained HTML error page.

import { Youch } from 'youch';
import http from 'node:http';

const server = http.createServer(async (req, res) => {
  try {
    if (req.url === '/error') {
      throw new Error('This is a simulated error for Youch to display!');
    }
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Visit /error to see Youch in action.');
  } catch (error) {
    const youch = new Youch();
    // The request object is optional, but provides valuable context.
    const html = await youch.toHTML(error, req);
    res.writeHead(500, { 'Content-Type': 'text/html' });
    res.end(html);
  }
});

const PORT = process.env.PORT ?? 3000;
server.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
  console.log('Open http://localhost:3000/error in your browser to trigger an error.');
});

view raw JSON →