{"library":"reserve","title":"REserve: Regex-Configurable HTTP Server","description":"REserve is a lightweight and versatile HTTP server package, currently at stable version 2.3.5. It specializes in serving static files, acting as a reverse proxy, and aggregating resources from multiple sources. The core functionality relies on declarative, regular expression-based mappings defined in a JSON configuration, offering fine-grained control over request routing and handling. The project demonstrates an active release cadence, with frequent minor updates and bug fixes. Its key differentiators include a minimal footprint with zero runtime dependencies, efficient performance (updated to `punycache`@`1.0.1` in v2.3.0), and the power of embedded regular expressions for highly flexible and dynamic server configurations, making it well-suited for development environments and complex routing scenarios without the overhead of larger frameworks.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install reserve"],"cli":{"name":"reserve","version":null}},"imports":["import { serve } from 'reserve'","import { Configuration } from 'reserve'","import { Server } from 'reserve'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { serve, Configuration, Server } from 'reserve';\nimport * as path from 'path';\n\nconst config: Configuration = {\n  port: 8080,\n  mappings: [\n    {\n      // Serve files from the current working directory\n      match: '^/(.*)',\n      file: path.join(process.cwd(), '$1') // Ensures serving from the correct absolute path\n    },\n    {\n      // Default catch-all for unmatched requests\n      status: 404\n    }\n  ]\n};\n\nlet serverInstance: Server | null = null; // To hold the server instance for graceful shutdown\n\nserve(config)\n  .on('ready', ({ url }: { url: string }) => {\n    serverInstance = serverInstance; // Capture the instance\n    console.log(`REserve server running at ${url}`);\n    console.log(`Try accessing http://localhost:${config.port}/package.json if this file exists in your current directory.`);\n  })\n  .on('error', (error: Error) => {\n    console.error('REserve server encountered an error:', error.message);\n  })\n  .on('abort', () => {\n    console.log('REserve server aborted.');\n  });\n\n// Implement graceful shutdown on process termination signals\nprocess.on('SIGINT', async () => {\n  console.log('SIGINT received. Shutting down REserve server...');\n  if (serverInstance) {\n    try {\n      await serverInstance.close();\n      console.log('REserve server gracefully closed.');\n    } catch (err) {\n      console.error('Error closing REserve server:', err);\n    }\n  }\n  process.exit(0);\n});\n\nprocess.on('SIGTERM', async () => {\n  console.log('SIGTERM received. Shutting down REserve server...');\n  if (serverInstance) {\n    try {\n      await serverInstance.close();\n      console.log('REserve server gracefully closed.');\n    } catch (err) {\n      console.error('Error closing REserve server:', err);\n    }\n  }\n  process.exit(0);\n});","lang":"typescript","description":"Demonstrates how to embed and start a `reserve` HTTP server in a TypeScript application with basic static file serving, including event handling for ready, error, and graceful shutdown on process signals.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}