{"id":17947,"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.","status":"active","version":"2.11.0","language":"javascript","source_language":"en","source_url":"https://github.com/greggman/servez-lib","tags":["javascript","http","https","server"],"install":[{"cmd":"npm install servez-lib","lang":"bash","label":"npm"},{"cmd":"yarn add servez-lib","lang":"bash","label":"yarn"},{"cmd":"pnpm add servez-lib","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily exports a single function, `createServez`, using CommonJS `module.exports`. Named ESM imports (`import { ... }`) will not work directly. The author strongly advises against using this library as an external dependency; consider copying its source code instead.","wrong":"import { createServez } from 'servez-lib';","symbol":"createServez","correct":"const createServez = require('servez-lib');"},{"note":"While `servez-lib` is a CommonJS package, Node.js allows default imports for CJS modules within ESM contexts. Ensure your project is configured for ESM if using this syntax (e.g., `\"type\": \"module\"` in package.json).","wrong":"const createServez = require('servez-lib'); // In an ESM module file","symbol":"createServez (ESM import)","correct":"import createServez from 'servez-lib';"},{"note":"As `servez-lib` is not intended for third-party consumption, it does not ship with explicit TypeScript declaration files. Users requiring type safety would need to create their own declaration files or rely on inferred types if using TypeScript.","symbol":"Types","correct":"// No dedicated TypeScript types are officially published or maintained for external use."}],"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."},"warnings":[{"fix":"Fork or copy the relevant source code files from `servez-lib` into your project, or choose a different, externally-maintained HTTP server library designed for public consumption and extension.","message":"The author explicitly states this library is not intended for external use or extension by third parties; instead, it's recommended to copy the source code directly into your project. Treating it as a general-purpose library will likely lead to unexpected breaking changes, lack of support, or unaddressed issues.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Do not rely on `servez-lib` for long-term external API stability. Any version update should be treated as potentially introducing breaking changes for third-party usage.","message":"API stability is not guaranteed for external consumers. Changes may be introduced without strict adherence to semantic versioning principles for third-party integrations, as the library primarily serves internal projects by the same author.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer CommonJS `require()` for maximum compatibility. If using ESM, use `import createServez from 'servez-lib';` and thoroughly test your application, especially for advanced features.","message":"The library is primarily designed for CommonJS (CJS) environments. While it can be imported in ESM projects using default import syntax, direct named ESM imports or explicit `package.json` `type: \"module\"` configurations might not be fully supported or tested for all functionalities.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change the `port` option in your `createServez` configuration to an unused port (e.g., 3000, 8000), or identify and terminate the conflicting process.","cause":"Another process on your machine is already using the specified port (e.g., 8080).","error":"Error: listen EADDRINUSE: address already in use :::8080"},{"fix":"Ensure the directory specified by the `root` option exists. Create it if necessary before starting the server, or correct the path if it's misspelled.","cause":"The `root` directory specified in the server options does not exist on your file system.","error":"Error: ENOENT: no such file or directory, stat '/path/to/nonexistent/root'"},{"fix":"Set the `index` option in `createServez` to the name of your desired index file (e.g., `index: 'index.html'`) and verify that this file exists directly within the `root` directory you are serving.","cause":"The `index` option might not be correctly configured, or the specified index file (e.g., `index.html`) is not present in the `root` directory.","error":"When accessing the server, I see a directory listing instead of my index.html page."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}