Another Express Framework is a lightweight, decorator-based Express.js framework inspired by NestJS. It provides a structured way to build scalable and maintainable server-side applications with TypeScript.
This framework is designed to be easily integrated into your project by copying the source code directly.
- Decorator-based routing and dependency injection
- Module-based architecture
- Built-in support for middleware, guards, pipes, and interceptors
- Exception filters for centralized error handling
- Configurable scopes for services (Singleton, Transient, Request)
- Easy integration with Express.js ecosystem
- Copy the framework source code to your project repository.
- Place the copied file in your project, for example, as
./src/framework/index.ts
. - Import the necessary decorators and classes from this file in your application code.
- Create a new TypeScript project and install the necessary dependencies:
npm init -y
npm install express @types/express typescript inversify qs reflect-metadata zod
-
Copy the framework source code as described in the Installation section.
-
Create a simple controller:
import { Controller, Get, Post, Body } from "./src/framework";
@Controller("/users")
export class UserController {
@Get()
getUsers() {
return [{ id: 1, name: "John Doe" }];
}
@Post()
createUser(@Body() user: any) {
// Create user logic
return user;
}
}
- Create a module to group related components:
import { Module } from "./src/framework";
import { UserController } from "./user.controller";
@Module({
controllers: [UserController],
})
export class AppModule {}
- Set up the main application:
import { MiniFramework } from "./src/framework";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = new MiniFramework();
await app.registerModule(AppModule);
app.listen(3000, () => console.log("Server running on port 3000"));
}
bootstrap();
Modules are used to organize the application structure. They encapsulate controllers, providers, and can import other modules.
Controllers are responsible for handling incoming requests and returning responses to the client.
Providers are injectable classes (services, repositories, etc.) that can be injected into controllers or other providers.
Middleware functions can be used to modify the request or response objects, end the request-response cycle, or call the next middleware function.
Guards determine whether a request should be handled by the route handler or not, typically used for authentication and authorization.
Pipes transform input data to the desired format or validate it before it reaches the route handler.
Interceptors can modify the response from route handlers before it's sent to the client.
Exception filters handle exceptions thrown from your application code and send appropriate error responses to the client.
For more advanced usage and detailed API documentation, please refer to the framework source code. The source code contains extensive comments and type definitions that can help you understand and use the framework's features.
Contributions are welcome! Please feel free to submit a Pull Request to the original repository.
This project is licensed under the MIT License.