In Express 5, mime is no longer an exported property of express.static. The mime-types package should be used to
work with MIME type values instead.
This codemod rewrites every express.static.mime reference to use a mime-types
binding and adds the corresponding import/require to the file:
Replaces express.static.mime with a mime-types local binding (default name mime).
Adds the import once per file, matching how express is imported
(import mime from 'mime-types' for ESM, const mime = require('mime-types') for CommonJS).
Reuses an existing mime-types import when the file already has one, and falls
back to a non-colliding name (mimeTypes) when mime is already taken.
The object Express 4 exposed as express.static.mime was a mime@1.x
instance, whose API is not identical to mime-types. The codemod rewrites
each member accordingly:
An existing mime-types entry is left untouched, and package.json files without express are not modified.
Notes
Behavior differs slightly even for the shared methods: mime-types returns false for unknown input, whereas mime@1.xlookup() fell back to default_type (application/octet-stream). Review code that relied on that
fallback.
Members flagged with a TODO comment (define, load, default_type) have no mime-types equivalent and must be migrated by hand.
Run npm install after the migration so the added mime-types dependency is installed.