Skip to content

vosonha89/typescript-express-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to typescript-express-basic 👋

Version Documentation Maintenance License: MIT

Basic api concept using typescript for express.

https://www.npmjs.com/package/typescript-express-basic

Concept

alt text

Install

Install express from https://expressjs.com/

npm install express --save

Install extend express basic

npm install typescript-express-basic --save

Optionals:

Swagger UI

Compatable with https://brikev.github.io/express-jsdoc-swagger-docs/#/README, included in the 'test' folder

https://brikev.github.io/express-jsdoc-swagger-docs/#/README

Creating example controller

export class PublicController extends ApiController {
    public controllerName = 'public';

    @ApiRoute({
        method: ApiMethod.GET,
        path: '/get'
    })
    public get(req: Request, res: Response): void {
        const id = req.query.id;
        res.status(StatusCode.Ok);
        res.send('Public get ' + id);
    }
}

Register app & controllers

const port = 3000;
let app = apiExpress;
app.use(express.json());

// Register controller
app.registerController(new PublicController());

app.listen(port, () => {
    console.log(`[server]: Server is running at http://localhost:${port}`);
});

Run test project

npm run test

Link: http://localhost:3000

Author

👤 vosonha89

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2024 vosonha89.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published