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.
npm install static-contentVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Node.js HTTP server to serve static files from a 'public' directory, including custom MIME types and caching.
For ESM projects, consider using a CommonJS compatibility layer or transpiling your code. If possible, stick to `require()` or use a different static serving middleware if ESM is a strict requirement.
Always explicitly define the `base` option in the `staticContent.create({ base: './your-static-folder' })` settings to ensure predictable file serving paths.Refer to the `atma-io` documentation for details on extending file reading capabilities. Install `atma-io` if you plan to implement custom file processing pipelines.
If your project is ESM, ensure your import statements are correctly configured for CommonJS modules, or use a tool like Rollup/Webpack to bundle. Consider using `createRequire` from the `module` built-in module for specific CJS imports in ESM.
Verify that the `base` path provided in `staticContent.create({ base: '...' })` is correct and relative to your application's execution directory, or an absolute path. Ensure the static files you are trying to serve actually exist in that location.