MIME Type from File Name
Easy · Files
A static file server must send the right Content-Type for each file. Write a function mimeType(fileName) that looks at the extension (the part after the last .), ignoring case:
- html → "text/html"
- css → "text/css"
- js → "text/javascript"
- json → "application/json"
- png → "image/png"
- jpg or jpeg → "image/jpeg"
- svg → "image/svg+xml"
- txt → "text/plain"
For anything else, including names without an extension, return "application/octet-stream".
Next: File Extension