What is @types/serve-static?
The @types/serve-static package contains TypeScript type definitions for the serve-static middleware, which is used with Node.js HTTP servers to serve static files. These type definitions allow TypeScript developers to use serve-static in a type-safe manner, ensuring that they use the correct types for function arguments, return types, and object properties.
Serve static files
This code sample demonstrates how to use serve-static with Express to serve static files from the 'public' directory. It also specifies that 'index.html' or 'index.htm' should be used as the default file to serve if a directory is requested.
import * as express from 'express';
import * as serveStatic from 'serve-static';
const app = express();
app.use(serveStatic('public', {'index': ['index.html', 'index.htm']}));
app.listen(3000, () => {
console.log('Server is running on port 3000');
});