Simple Command-Line HTTP Server

2.4.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');

const publicDir = path.join(__dirname, 'public');
if (!fs.existsSync(publicDir)) {
  fs.mkdirSync(publicDir);
}
fs.writeFileSync(path.join(publicDir, 'index.html'), '<h1>Hello, Servez from JS!</h1>');
fs.writeFileSync(path.join(publicDir, 'style.css'), 'body { font-family: sans-serif; }');

console.log('Starting servez...');
const servezProcess = spawn('npx', ['servez', publicDir, '--port', '8080', '--dirs', '--cors', '--qr', '--local', '--index'], {
  stdio: 'inherit',
  shell: true // Needed on Windows for npx to be found
});

servezProcess.on('error', (err) => {
  console.error('Failed to start servez process:', err);
});

servezProcess.on('exit', (code) => {
  console.log(`servez process exited with code ${code}`);
});

console.log('Server should be available at http://localhost:8080');
console.log('Press Ctrl+C to stop this script and the servez server.');

view raw JSON →