{"library":"servez-lib","title":"Servez Library","description":"Servez-lib, currently at version 2.11.0, is a minimalist HTTP/HTTPS server library primarily designed for internal use within the author's related projects, `servez-cli` and the `servez` web application. It provides basic static file serving capabilities with configurable ports and root directories, including support for index files and logging. The library is explicitly not intended for external consumption or extension by third-party developers; its maintainer strongly recommends copying its source code directly into projects rather than establishing a package dependency. While it offers a simple way to create a local development server, its release cadence and API stability are not managed with external users in mind, making it an unsuitable choice for general-purpose library development. It offers core functionalities like serving index files and basic request handling through a straightforward API.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install servez-lib"],"cli":null},"imports":["const createServez = require('servez-lib');","import createServez from 'servez-lib';","// No dedicated TypeScript types are officially published or maintained for external use."],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const createServez = require('servez-lib');\nconst path = require('path');\nconst fs = require('fs');\n\nconst port = process.env.PORT ?? 8080;\nconst rootDir = path.join(__dirname, 'public');\nconst indexFile = 'index.html';\n\n// Ensure the 'public' directory exists and contains an index.html for demonstration\nif (!fs.existsSync(rootDir)) {\n  fs.mkdirSync(rootDir, { recursive: true });\n}\nif (!fs.existsSync(path.join(rootDir, indexFile))) {\n  fs.writeFileSync(path.join(rootDir, indexFile), `<!DOCTYPE html>\\n<html lang=\"en\">\\n<head>\\n    <meta charset=\"UTF-8\">\\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\\n    <title>Servez Quickstart</title>\\n</head>\\n<body>\\n    <h1>Hello from servez-lib!</h1>\\n    <p>This page is served from the '${path.basename(rootDir)}' directory.</p>\\n    <p>Server running on port ${port}.</p>\\n</body>\\n</html>`);\n}\n\nasync function startServer() {\n  try {\n    const serverOptions = {\n      port: port,\n      root: rootDir,\n      index: indexFile,\n      log: true\n    };\n\n    const server = await createServez(serverOptions);\n    console.log(`Servez server started successfully.`);\n    console.log(`Serving files from: ${server.root}`);\n    console.log(`Access at: http://localhost:${server.port}`);\n\n    process.on('SIGINT', async () => {\n      console.log('\\nShutting down Servez server...');\n      await server.kill();\n      console.log('Servez server shut down.');\n      process.exit(0);\n    });\n\n  } catch (error) {\n    console.error('Failed to start Servez server:', error);\n    process.exit(1);\n  }\n}\n\nstartServer();","lang":"javascript","description":"This example demonstrates how to initialize and start a basic HTTP server using `servez-lib` to serve static files from a 'public' directory, handling graceful shutdown.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}