{"library":"server-base","title":"Server Base","description":"server-base is a foundational package designed for quickly setting up HTTP microservices or simple web servers. Currently at version 7.1.32, it provides core functionalities such as declarative request routing, middleware integration, and automatic `.env` file loading for configuration management. It leverages `server-base-router` for its routing engine and integrates structured logging capabilities via `server-base-log`, which itself builds upon `pino` for high-performance logging. Additionally, it uses `fast-json-stringify` for optimized JSON serialization. While the README doesn't specify a precise release cadence, its active development and frequent version updates suggest ongoing maintenance. Its key differentiator lies in its opinionated, modular approach to server development, focusing on simplicity, performance, and testability for small to medium-sized services, abstracting away common boilerplate found in more comprehensive frameworks.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install server-base"],"cli":null},"imports":["const service = require('server-base')","import service from 'server-base'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const service = require('server-base');\n\nservice({\n  '@setup': (ctx, router) => {\n    // Example middleware: a simple pass-through. ctx.use() expects an array of middleware.\n    ctx.use([\n      (req, res, next) => {\n        console.log(`Incoming request: ${req.method} ${req.url}`);\n        next();\n      }\n    ]);\n    // Middleware can also be added directly to the router if server-base-router allows.\n  },\n  '/graphql': {\n    get (req, res) {\n      res.setHeader('Content-Type', 'text/html');\n      res.end('<h1>GraphQL Playground (GET)</h1><p>Not implemented yet.</p>');\n    },\n    async post (req, res) {\n      try {\n        const query = await req.json(); // Parses JSON body from request\n        // In a real app, process the GraphQL query here\n        console.log('Received GraphQL query:', query);\n        res.json({ data: { message: 'Query received!', query: query } }); // Sends JSON response\n      } catch (error) {\n        console.error('Error processing GraphQL POST:', error);\n        res.statusCode = 400;\n        res.json({ errors: [{ message: 'Invalid JSON or query.' }] });\n      }\n    }\n  },\n  '/health': {\n    get (req, res) {\n      res.json({ status: 'ok', uptime: process.uptime() });\n    }\n  }\n})\n.start(process.env.PORT ?? 5000)\n.then(() => console.log(`Server started on port ${process.env.PORT ?? 5000}`));","lang":"javascript","description":"Initializes a `server-base` instance, setting up global middleware in the `@setup` hook and defining two API endpoints: a `/graphql` path with GET and async POST handlers (demonstrating JSON parsing), and a `/health` endpoint.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}