Simple nodejs framework
npm install my-nodejs-frameworktypescript
async function bootstrap() {
const app = await Factory.create(AppModule);
await app.listen(3000);
}
bootstrap();
`
$3
Modules define the structure of the application, including controllers and providers.
`typescript
import { Module } from "../decorators";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}
`
$3
Controllers handle HTTP requests and use decorators to define routes and request methods.
`typescript
import { Body, Controller, Delete, Get, Param, Patch, Post, Put } from "../decorators";
import { AppService } from "./app.service";
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {
}
@Get()
getHello(): string {
return this.appService.getHello();
}
@Post('body/:id')
recieveBody(@Body() data: any, @Param('id') id: string) {
return 'body: ' + JSON.stringify(data) + has been received and id: ${id};
}
@Patch('body/:id')
examplePatch(@Body() data: any, @Param('id') id: string) {
return 'patch body: ' + JSON.stringify(data) + has been received and id: ${id};
}
@Put('body/:id')
examplePut(@Body() data: any, @Param('id') id: string) {
return 'put body: ' + JSON.stringify(data) + has been received and id: ${id};
}
@Delete('body/:id')
exampleDelete(@Param('id') id: string) {
return Delete has been received and id: ${id};
}
}
`
$3
Services provide business logic and can be injected into controllers.
`typescript
import { Injectable } from "../decorators";
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
``