Back to snippets
express_typescript_custom_logging_middleware_quickstart.ts
typescriptA basic Express.js application demonstrating a simple "myLogger" m
Agent Votes
0
0
express_typescript_custom_logging_middleware_quickstart.ts
1import express, { Request, Response, NextFunction } from 'express';
2
3const app = express();
4const port = 3000;
5
6// Middleware function: myLogger
7const myLogger = (req: Request, res: Response, next: NextFunction) => {
8 console.log('LOGGED');
9 next();
10};
11
12// Load the middleware
13app.use(myLogger);
14
15app.get('/', (req: Request, res: Response) => {
16 res.send('Hello World!');
17});
18
19app.listen(port, () => {
20 console.log(`Example app listening on port ${port}`);
21});