1.0.4 • Published 10 months ago

nast.ge v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

NastJS

NastJS is a lightweight framework inspired by NestJS, designed to simplify building scalable and modular Node.js applications.

By default, the application runs on http://localhost:3000.

Creating Modules, Controllers, and Services

To create a new module, controller, and service using NastJS, follow these steps:

  1. Create a new TypeScript file for your module:
// mymodule.module.ts
import { Module } from "../nast/decorators/module.decorator";
import { MyController } from "./mycontroller.controller";
import { MyService } from "./myservice.service";

@Module({
  provider: [MyService],
  controller: [MyController],
  exports: [],
  imports: [],
})
export class MyModule {}
  1. Create a new TypeScript file for your controller:
// mycontroller.controller.ts
import { Controller } from "../nast/decorators/controller.decorator";
import { Get, Post } from "../nast/decorators/http.decorator";
import { MyService } from "./myservice.service";
import { NastRequest } from "../nast/types/types";

@Controller()
export class MyController {
  constructor(private readonly myService: MyService) {}

  @Get("/myroute")
  handleGetRequest(req: NastRequest) {
    // Handle GET request
  }

  @Post("/myroute")
  handlePostRequest(req: NastRequest) {
    // Handle POST request
  }
}
  1. Create a new TypeScript file for your service:
// myservice.service.ts
import { Injectable } from "../nast/decorators/injectable.decorator";

@Injectable("myService")
export class MyService {
  // Service methods and business logic here
}

Dependency Injection

NastJS provides a simple dependency injection system. To use it, follow these steps:

  1. Decorate your service with the @Injectable decorator:
import { Injectable } from "../nast/decorators/injectable.decorator";

In Injectable decorator, you have to put argument a key of service, than u should
use this key in a controller or anywhere u have to use it.

@Injectable("myService")
export class MyService {
  // ...
}
  1. Inject the service into your controller or other services:
import { Controller } from "../nast/decorators/controller.decorator";
import { MyService } from "./myservice.service";

@Controller()
export class MyController {
  constructor(private readonly myService: MyService) {
    // ...
  }

  // ...
}

Routing

NastJS provides decorators to define routes within your controllers. Here's an example:

import { Controller } from "../nast/decorators/controller.decorator";
import { Get, Post } from "../nast/decorators/http.decorator";
import { MyService } from "./myservice.service";
import { NastRequest } from "../nast/types/types";

@Controller("/users")
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get("/getUser")
  getUser(req: NastRequest) {
    // Handle GET request for user retrieval
  }

  @Post("/createUser")
  createUser(req: NastRequest) {
    // Handle POST request for user creation
  }
}

The @Controller decorator sets the base path for all routes defined within the controller.

Contributing

Contributions to NastJS are welcome! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes and push them to your fork.
  4. Submit a pull request with a clear description of your changes.

License

ISC

Please note that the above README assumes that you have cloned the NastJS repository and have access to the source files in the provided structure. Adjust the instructions as necessary based on your project's setup.
1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago