{"library":"static-server","title":"Node.js Static File Server","type":"library","description":"The `static-server` package provides a minimalistic HTTP server explicitly designed to serve static files from a local directory. It is primarily intended for local development, rapid prototyping, or testing scenarios, with its maintainers stating it is \"obviously not\" suitable for production environments and \"preferably not\" for high-traffic applications. The current stable version, 2.2.1, was released several years ago, and the project appears to be abandoned, with no significant updates in a long time. It differentiates itself by its extreme simplicity and minimal configuration options, serving only static resources without support for server-side scripting languages like PHP, Ruby, or Python. It's a foundational utility rather than a feature-rich web server.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install static-server"],"cli":{"name":"static-server","version":null}},"imports":["var StaticServer = require('static-server');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/nbluis/static-server","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/static-server","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"var StaticServer = require('static-server');\nvar server = new StaticServer({\n  rootPath: '.',            // required, the root of the server file tree\n  port: 1337,               // required, the port to listen\n  name: 'my-http-server',   // optional, will set \"X-Powered-by\" HTTP header\n  host: '127.0.0.1',        // optional, defaults to any interface (use '127.0.0.1' for local only)\n  cors: '*',                // optional, defaults to undefined, '*' allows all origins\n  followSymlink: true,      // optional, defaults to a 404 error if not true\n  templates: {\n    index: 'index.html',    // optional, defaults to 'index.html'\n    notFound: '404.html'    // optional, defaults to undefined\n  }\n});\n\nserver.start(function () {\n  console.log('Server listening to', server.port);\n  console.log('Serving files from', server.rootPath);\n  // Create a dummy index.html for demonstration\n  require('fs').writeFileSync('index.html', '<h1>Hello from static-server!</h1>');\n  console.log('Created a temporary index.html. Access at http://' + server.host + ':' + server.port);\n});\n\nserver.on('request', function (req, res) {\n  // Log basic request info\n  console.log(`Request for ${req.path} took ${req.elapsedTime}`);\n});\n\nserver.on('response', function (req, res, err, file, stat) {\n  // Note: the response has already been sent at this point\n  if (err) {\n    console.error(`Error serving ${req.path}: ${err.message}`);\n  } else if (file) {\n    console.log(`Served ${file} with status ${res.status}`);\n  }\n});","lang":"javascript","description":"This quickstart initializes and starts a static HTTP server on port 1337, serving files from the current directory. It demonstrates basic event listeners for requests and responses, and explicitly enables CORS and symlink following. A temporary `index.html` is created for immediate testing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}