{"library":"local-web-server","title":"Local Web Server","description":"local-web-server is a lean, modular web server designed for rapid full-stack development. As a distribution of the core `lws` package, it bundles a starter pack of useful middleware, enabling functionalities like serving static files, Single Page Applications (SPAs), URL rewriting, CORS, and mock APIs out-of-the-box. The current stable version is 5.4.0, with regular updates addressing bug fixes and new features. It supports HTTP, HTTPS, and HTTP2, offering both programmatic and command-line interfaces. Key differentiators include its small footprint, modular design allowing users to load only required behaviors, and comprehensive features for prototyping back-end services or front-end applications. It requires Node.js v12.20 or newer.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install local-web-server"],"cli":{"name":"ws","version":null}},"imports":["import createServer from 'local-web-server'","import type { LwsOptions } from 'lws'","npx ws [options]"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import createServer from 'local-web-server';\n\n// Create a server instance with common development features\nconst server = createServer({\n  port: process.env.PORT ? parseInt(process.env.PORT) : 8000,\n  // Serve static files from the current directory\n  // local-web-server includes static serving by default if 'root' is not specified.\n  // This explicitly sets the root to the 'public' directory if it exists.\n  root: './public',\n  // Enable Single Page Application (SPA) routing, redirecting all non-file requests to index.html\n  spa: 'index.html',\n  // Enable CORS for all origins, useful for local development with separate API servers\n  cors: true,\n  // Rewrite API requests to a remote backend\n  rewrite: {\n    '/api/(.*)': 'https://jsonplaceholder.typicode.com/$1'\n  },\n  // Display a QR code in the terminal for easy mobile access\n  qr: true,\n  // Log requests in 'dev' format\n  log: 'dev'\n});\n\nserver.start();\nconsole.log(`Local Web Server running at http://localhost:${server.port}`);\nconsole.log(`Serving static files from: ${server.options.root || './'}`);","lang":"typescript","description":"This quickstart demonstrates programmatically configuring a local web server for SPA routing, API rewriting, CORS, and logging.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}