1.0.12 • Published 3 years ago

@nesa-js/core v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Introduction

Nesa Js is Allows to create controller classes with methods as actions that handle requests.

You can use Nesa Js with express.js and in the future with koa.js or fastify.

Installation

npm install @nesa-js/di
npm install @nesa-js/core

Example of usage

Here's example of usage with Express framework. It uses TypeScript and @nesa-js/core package.

main.ts

import express from "express";
import { attachControllers } from "@nesa-js/core";

export class App {
  private app: express.Application = express();
  private port: Number = 3000;

  public constructor() {
    this.bootstrap();
  }

  private bootstrap() {
    this.attachControllers();
    this.listen();
  }

  private attachControllers() {
    attachControllers(this.app, [__dirname + "/Controllers/**/*Controller{.ts,.js}"]);
  }

  private listen() {
    this.app.listen(this.port, () => {
      console.log(`🚀 Server is listening on http://localhost:${this.port}`);
    });
  }
}

new App();

UserController.ts

import { Injectable } from "@nesa-js/di";
import { Controller, Get, Response } from "@nesa-js/core";
import { UserService } from "../Services/UserService";

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

  @Get("/")
  async getAll(@Response() response) {
    const users = this.userService.getAll();

    return response.json(users);
  }
}

Check how to use in real aplication.

Documentation

Look at the corresponding package for instructions.

1.0.12

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago