{"library":"lws","title":"Lws: Lean, Modular Web Server","description":"Lws is a lean, modular web server designed for rapid full-stack development, serving as an application core for quickly launching local HTTP, HTTPS, and HTTP2 servers. Its behavior is entirely customizable through a plugin system built on Koa middleware, allowing users to load only the specific functionalities required for their projects. Key differentiators include its small footprint, 100% personalizable nature, support for custom views for activity visualization, and both programmatic and command-line interfaces. The current stable version is 4.2.0. The project maintains an active release cadence, with recent updates focusing on Node.js compatibility and refining its modular plugin architecture.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install lws"],"cli":{"name":"lws","version":null}},"imports":["import Lws from 'lws';","import Lws from 'lws';","import MyPlugin from './my-plugin.js';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Lws from 'lws';\nimport { resolve } from 'path';\n\n// Define a simple Koa-style middleware plugin\nclass HelloWorldPlugin {\n  middleware() {\n    return async (ctx, next) => {\n      // Serve a custom response for the root path\n      if (ctx.path === '/') {\n        ctx.body = 'Hello from Lws! This is a programmatic server.';\n        ctx.type = 'text/plain';\n        return; // Prevent further middleware from processing this request\n      }\n      // Allow other middleware to handle the request\n      await next();\n    };\n  }\n}\n\n// Define another simple middleware to catch unhandled requests\nclass NotFoundPlugin {\n  middleware() {\n    return async (ctx, next) => {\n      await next();\n      // If the request was not handled by any preceding middleware\n      if (!ctx.body) {\n        ctx.body = '404 Not Found from Lws Custom Stack!';\n        ctx.status = 404;\n        ctx.type = 'text/plain';\n      }\n    };\n  }\n}\n\nasync function startLwsServer() {\n  const server = new Lws({\n    port: 8000,\n    // The `stack` option accepts an array of plugin instances.\n    stack: [\n      new HelloWorldPlugin(),\n      new NotFoundPlugin()\n      // To use external plugins like lws-static, ensure they are installed:\n      // { module: require('lws-static'), options: { directory: resolve(process.cwd(), 'public') } }\n    ]\n  });\n\n  server.start();\n  console.log(`Lws server listening on http://localhost:${server.port}`);\n  console.log('Test by visiting: http://localhost:8000/');\n  console.log('Test 404 by visiting: http://localhost:8000/non-existent-path');\n}\n\nstartLwsServer().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically initialize and start an Lws server, including how to define and register simple inline Koa-style middleware to handle requests and serve custom responses for specific paths.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}