1.0.3 • Published 3 years ago

@webgeek/basic-express-decorators v1.0.3

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

basic-express-decorators

Basic Decorators for Express - Includes supports for express-validator using Typescript

Checkout this repository https://github.com/jbeduya/basic-express-decorators-demo for more information.

Installation

npm install @webgeek/basic-express-decorators

Update your tsconfig.json

Enable the following:

{
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}

Usage

Let's say you have controllers folder. Create two files under it.

home.ts

import { controller, get } from "basic-express-decorators";
import { Request, Response } from 'express';

@controller()
export class HomeController {
    @get('/')
    index(req: Request, res: Response) {
        res.send('Hello World')
    }

    @get('/demo')
    demo(req: Request, res: Response) {
        res.json({ message: 'This is just a demo'})
    }
}

index.ts

export * from './home'

In your express app, do the following:

import express from 'express';
import { Router } from 'basic-express-decorators'
import './controllers'

const app = express();
app.use(Router.getInstance())

app.listen(8000, () => console.log('Listening at http://localhost:8000'))