⚠️ Note: This is an experimental side project meant for learning and demonstration purposes. It is not production-ready and should not be used in production environments without significant hardening, testing, and security reviews.
View on GitHub> git clone https://github.com/djokobozinov/express-ts.git
> npm install
> npm start
This project demonstrates a TypeScript-based Express.js application with decorators for clean and declarative route handling.
In your main application file (e.g., index.ts
), register your controllers:
registerRoutes(app, [UserController]);
Create a controller class using decorators to define routes and middleware:
import { Request, Response } from 'express'; import { Controller, Get, RateLimit } from './path/to/decorators'; @Controller('/api/users') export class UserController { @Get('/') @RateLimit(100, 60000) // 100 requests per minute public async getUsers(req: Request, res: Response) { console.log('getUsers'); res.json({ message: 'getUsers' }); } @Get('/:id') public async getUserById(req: Request, res: Response) { console.log('getUserById', req.params.id); res.json({ message: 'getUserById', id: req.params.id }); } @Post('/') public async createUser(req: Request, res: Response) { console.log('createUser', req.body); res.json({ message: 'createUser', body: req.body }); } }
Once your server is running, you can test the API endpoint by visiting:
http://localhost:3000/api/users
Feel free to contribute, fork, or use this project in any way you'd like! This is an open experiment and learning resource.
No restrictions - have fun exploring and experimenting!