{"library":"spa-http-server","title":"http-server Command-Line Static Server","type":"library","description":"http-server is a zero-configuration command-line HTTP server designed for serving static files, widely used for local development, testing, and production deployments. It is currently in a stable state with version `v14.1.1` as its latest release. The project maintains an active release cadence, providing frequent patches for security vulnerabilities and dependency updates, alongside less frequent major versions that introduce breaking changes and new features. A key differentiator is its simplicity and ease of use, enabling developers to spin up a server with a single command, automatically serving `./public` if it exists, otherwise the current directory. While primarily a CLI tool, it also exposes a programmatic API for integration into Node.js applications, adhering to CommonJS module standards.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install spa-http-server"],"cli":{"name":"http-server","version":null}},"imports":["const http = require('http-server');","const { createServer } = require('http-server');","import type { HttpServerOptions } from 'http-server';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/indexzero/http-server","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/spa-http-server","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"// Install http-server globally\n// npm install -g http-server\n\n// Navigate to your project directory\n// cd my-static-app\n\n// Start the server, serving the current directory\n// Opens a browser window by default on http://localhost:8080\nhttp-server -o\n\n// Alternatively, specify a port, disable caching, and enable CORS\n// http-server . -p 3000 --cors -c-1\n\n// Programmatic example (save as server.js and run `node server.js`)\nconst { createServer } = require('http-server');\nconst path = require('path');\n\nconst server = createServer({\n  root: path.join(__dirname, 'public'), // Serve files from a 'public' subdirectory\n  cache: -1, // Disable caching for development\n  cors: true, // Enable CORS\n  showDir: true, // Show directory listings\n  autoIndex: true, // Display autoIndex\n  headers: { // Custom headers can be useful, e.g., for security or features\n    'X-Custom-Header': 'Hello from http-server'\n  }\n});\n\nserver.listen(8080, '0.0.0.0', () => {\n  console.log('HTTP Server listening on http://0.0.0.0:8080');\n  console.log('Serving directory:', path.join(__dirname, 'public'));\n});","lang":"javascript","description":"Demonstrates global installation and basic CLI usage, alongside a programmatic setup serving static files with custom options, including CORS and caching control.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}