Starter Kits - ds-express-errors


Don't want to configure everything manually? Download a ready-to-run Express project pre-configured with ds-express-errors.

Each kit includes: express, nodemon, and ds-express-errors@1.7.1


Kit structure:

index.jspackage.json.gitignoreREADME


1. Basic Starter


The simplest setup. Perfect for small projects or learning how the library works. Includes basic error handling middleware setup.

2. Production Ready (Graceful Shutdown)


Best for production applications. Includes initGlobalHandlers configuration to safely handle uncaughtException and unhandledRejection, ensuring your server closes database connections before exiting.

javascript
initGlobalHandlers({
  closeServer: gracefulHttpClose(server), // Gracefully close server
  onShutdown: async (signal) => {
    console.log('Cleaning up...');
    await mongoose.disconnect(); // Close DB connections
  },
  onCrash: async (err, signal) => {
    await sendAlertToAdmin(err); // Notify dev team about crash
  }
});

3. Custom Configuration


Includes pre-configured setConfig. Use formatError if you need to change the default JSON response structure (e.g., removing the url field or renaming status to success).

Flexible environment configuration via devEnvironments

Inject your own logic into the error handling pipeline with customMappers

javascript
setConfig({
  customLogger: null, // use if you want to set your custom logger
  devEnvironments: ['development', 'local', 'staging'],
  customMappers: [
    // req is optional argument
    (err) => {
      // Example: Handle a specific error from a payment gateway
      if (err.name === 'StripeCardError') {
        return Errors.PaymentRequired(err.message);
      }
      //... other if
      
      // Return null/undefined to let the library handle other errors
    }
    // (err, req) => ...
  ],
  // Use destructuring to access req and isDev from the second argument
  formatError: (err, { req, isDev }) => ({
    success: false,
    error: {
        code: err.statusCode,
        message: err.message,
        url: req.originalUrl, // Access request details
        // Add stack trace only in development
        ...(isDev ? { debug_stack: err.stack } : {}) 
    }
  })
});

4. All-In-One Ultimate


Combines everything: Custom Configuration + Graceful Shutdown. The most robust starting point for serious enterprise-grade applications.