{"library":"lws-mime","title":"lws-mime: Local Web Server MIME Type Middleware","description":"lws-mime is a middleware designed for the `lws` (local-web-server) ecosystem, enabling developers to customize and override default HTTP response MIME types. Currently stable at version 2.0.0, released in 2017, this package is in maintenance mode, providing a robust and tested solution without frequent updates, but relies on the actively developed `lws` core. Its primary differentiator is deep integration with `lws`, offering programmatic control over how file extensions map to MIME types, thereby ensuring web assets are served with the correct `Content-Type` headers. This is crucial for proper browser rendering and interpretation, especially for custom file formats or when standard MIME sniffing is insufficient. While other general `mime` libraries exist, lws-mime offers a tailored solution for `lws` deployments.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install lws-mime"],"cli":null},"imports":["const lwsMime = require('lws-mime');","const lwsMime = require('lws-mime');\n// Pass directly to lws configuration stack\n{\n  module: lwsMime,\n  options: { 'myext': 'application/x-my-format' }\n}"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const lws = require('lws');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create a dummy file with a custom extension\nconst filePath = path.join(__dirname, 'example.custom');\nfs.writeFileSync(filePath, '{\"message\": \"Hello, custom world!\"}', 'utf8');\n\nconst server = lws.create({\n  stack: [\n    // lws-mime middleware to define custom MIME types\n    { module: require('lws-mime'), options: { 'custom': 'application/vnd.my-custom-format+json' } },\n    // lws-static to serve the file\n    { module: require('lws-static'), options: { root: __dirname } }\n  ],\n  port: 8000\n});\n\nserver.listen(() => {\n  console.log('Server running on http://localhost:8000');\n  console.log('Try accessing: http://localhost:8000/example.custom');\n  console.log('The response should have Content-Type: application/vnd.my-custom-format+json');\n});\n\n// Clean up dummy file on process exit\nprocess.on('exit', () => {\n  if (fs.existsSync(filePath)) {\n    fs.unlinkSync(filePath);\n  }\n});","lang":"javascript","description":"Demonstrates how to start an `lws` server, integrate `lws-mime` middleware, and define a custom MIME type for a specific file extension.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}