{"library":"static-content","title":"HTTP Static Content Middleware for Node.js","type":"library","description":"This middleware is part of the `atmajs` ecosystem, designed for handling static file serving in Node.js HTTP servers. It provides features like caching, gzipping, and range requests for optimized delivery of various content types including HTML, scripts, images, and videos. It supports custom MIME types, encoding configurations, and integrates seamlessly with `atma-server` and Connect-style middleware stacks. Currently at version 1.2.2, its release cadence is not explicitly defined, but it appears to be a stable, mature component within its specific framework, primarily targeting CommonJS environments. Key differentiators include its tight integration with `atma-io` for advanced file reading and its support for virtual files and custom file `read` middlewares, offering more flexibility than generic static servers.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install static-content"],"cli":null},"imports":["const StaticContentMiddleware = require('static-content');","const createStaticMiddleware = require('static-content').create;","const StaticCache = require('static-content').Cache;"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://atma.js.org","github":"https://github.com/atmajs/atma-server-static","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/static-content","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const http = require('http');\nconst staticContent = require('static-content');\n\n// Create a static content middleware instance\nconst staticMiddleware = staticContent.create({\n    base: './public',\n    mimeTypes: {\n        'application/javascript': ['mjs']\n    },\n    extensions: {\n        'text/html': {\n            encoding: 'UTF-8',\n            maxAge: 3600 // Cache for 1 hour\n        }\n    }\n});\n\n// Create a simple HTTP server using the middleware\nhttp.createServer((req, res) => {\n    // The middleware handles static content requests\n    staticMiddleware(req, res, () => {\n        // If static content is not found, handle dynamic content or return 404\n        res.writeHead(404, { 'Content-Type': 'text/plain' });\n        res.end('404 Not Found');\n    });\n}).listen(5777, () => {\n    console.log('Static server running on http://localhost:5777');\n    console.log('Serving files from ./public');\n});\n","lang":"javascript","description":"Demonstrates setting up a basic Node.js HTTP server to serve static files from a 'public' directory, including custom MIME types and caching.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}