{"id":12012,"library":"servez","title":"Simple Command-Line HTTP Server","description":"Servez is a straightforward command-line HTTP server designed for local development and learning, serving static files quickly. As of version 2.4.0, it offers zero-configuration defaults but provides a rich set of options for customization, including port selection, directory listing, CORS headers, gzip/brotli compression, and basic authentication. Its primary differentiator is its simplicity and ease of use, aiming to replace tools like `http-server` with a modern, actively maintained alternative. It supports both HTTP and HTTPS (with self-signed or custom certificates) and can display QR codes for easy mobile access. The project appears to have a regular, albeit not fixed, release cadence, driven by user needs and feature enhancements, making it a reliable choice for development server needs.","status":"active","version":"2.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/greggman/servez-cli","tags":["javascript","http","https","server","cli","command"],"install":[{"cmd":"npm install servez","lang":"bash","label":"npm"},{"cmd":"yarn add servez","lang":"bash","label":"yarn"},{"cmd":"pnpm add servez","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This refers to executing the 'servez' command after a global npm installation. It is primarily a CLI tool and not designed for direct programmatic import as a JavaScript module.","wrong":"import servez from 'servez';","symbol":"servez","correct":"servez [options] [path]"},{"note":"Using 'npx' allows you to execute 'servez' on-demand without a global installation, ensuring you use the latest version or a specific version by appending '@<version>'.","symbol":"npx servez","correct":"npx servez [options] [path]"},{"note":"This command installs the 'servez' executable globally on your system, making it accessible from any directory in your terminal.","wrong":"require('servez').installGlobal();","symbol":"npm install -g servez","correct":"npm install -g servez"}],"quickstart":{"code":"const { spawn } = require('child_process');\nconst path = require('path');\nconst fs = require('fs');\n\nconst publicDir = path.join(__dirname, 'public');\nif (!fs.existsSync(publicDir)) {\n  fs.mkdirSync(publicDir);\n}\nfs.writeFileSync(path.join(publicDir, 'index.html'), '<h1>Hello, Servez from JS!</h1>');\nfs.writeFileSync(path.join(publicDir, 'style.css'), 'body { font-family: sans-serif; }');\n\nconsole.log('Starting servez...');\nconst servezProcess = spawn('npx', ['servez', publicDir, '--port', '8080', '--dirs', '--cors', '--qr', '--local', '--index'], {\n  stdio: 'inherit',\n  shell: true // Needed on Windows for npx to be found\n});\n\nservezProcess.on('error', (err) => {\n  console.error('Failed to start servez process:', err);\n});\n\nservezProcess.on('exit', (code) => {\n  console.log(`servez process exited with code ${code}`);\n});\n\nconsole.log('Server should be available at http://localhost:8080');\nconsole.log('Press Ctrl+C to stop this script and the servez server.');\n","lang":"javascript","description":"Demonstrates how to programmatically start `servez` from a Node.js script, creating a public directory with sample content and serving it on port 8080 with directory listings, CORS, QR code, and local access enabled."},"warnings":[{"fix":"Always include `--local` if you intend for the server to be accessible only from `127.0.0.1` (localhost).","message":"By default, `servez` serves on all network interfaces (0.0.0.0), making it publicly accessible on your local network. To restrict access only to the local machine, use the `--local` option.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"For secure development, either configure your browser to trust the self-signed certificate, or provide valid, trusted certificates using `--cert` and `--key`.","message":"When using `--ssl` without specifying `--cert` and `--key` paths, `servez` generates a self-signed (fake) SSL certificate. Browsers will typically warn about this as the certificate is not trusted by a recognized Certificate Authority.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Check the server output in the terminal to confirm the exact port being used, or explicitly specify a port with `--port <number>`.","message":"If the default port 8080 is already in use, `servez` will automatically scan for and use the next available port. Users might inadvertently connect to a different port than expected.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Install Node.js via `nvm` (mac/linux) or `nvm-windows` (windows) before attempting to install or run `servez`.","message":"The `servez` CLI tool requires Node.js to be installed on your system. Using a Node Version Manager (like nvm or nvm-windows) is highly recommended to manage Node.js versions effectively.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install it globally via `npm install -g servez` or execute it directly using `npx servez`.","cause":"The `servez` command is not available in your system's PATH.","error":"servez: command not found"},{"fix":"Ensure `servez` is running and check the console output for the correct URL (e.g., `http://localhost:8080` or the next available port). If using `--local`, confirm you're accessing `127.0.0.1`.","cause":"The `servez` server is not running, or it's running on a different port/address than you're trying to access.","error":"ERR_CONNECTION_REFUSED"},{"fix":"Start `servez` with the `--cors` option to enable CORS headers: `servez --cors`.","cause":"Your browser is blocking a cross-origin request because the `servez` server did not send the necessary CORS headers.","error":"Access to fetch at 'http://localhost:8080/data.json' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."},{"fix":"For development, you can usually proceed past the browser warning. For a trusted setup, provide your own valid SSL certificate and key files using `--cert <path_to_cert>` and `--key <path_to_key>`.","cause":"You are using HTTPS (`--ssl`) with a self-signed certificate that your browser does not implicitly trust.","error":"NET::ERR_CERT_AUTHORITY_INVALID"}],"ecosystem":"npm"}