3 ms·
Ask HN: Best way to structure/architect an API with ExpressJS/TypeScript?
I've got major maintainability problems with my kind of amateurish webapp. I spent a bit of time the other day writing a bunch code that I just found out I had already written awhile back. I see a bunch of guides on Google but it's hard to judge how good they are without references/reviews. Are there some in depth guides on separation of concerns, service-oriented architecture, MVC, file structure, etc using Express? Or perhaps a really good reference project or two?
- wgallagher 5y agoI use and like FoalTS. It is a typescript server framework layered over express. It has good documentation, is opinionated about structure and provides a decent CLI for adding controllers, entities, tests, etc. It also includes typeorm for database entity integration. As a bonus OpenAPI support is included to help automate documentation generation for your REST API.
- riemann 5y agoFrameworks can help in this situation to some extent, but if going frameworkless is okay for you, Francesco Strazzullo's book "Frameworkless Front-End Development" did an excellent job of explaining what, why, and how to organize a js codebase without using external codebase, at least it did for me.
- gitgud 5y agoThere's no best way to architect anything. It's always a trade-off and depends tightly on your situation. Here's some practical advice. I would just look at loads of starter projects by googling "express typescript starter github" then explore each project. Things to remember when searching: - Most starter projects have too many use cases, so you can actually delete parts you don't need. - You don't need to use a single architecture, it may be better to combine things you like about a few different types
- bacbilla 5y agoI honestly recommend TSOA (https://github.com/lukeautry/tsoa https://github.com/lukeautry/tsoa) For me it provides enough structure without being a super opinionated framework. It handles route and doc generation based off your models and controllers, but everything else is up to you, which is perfect for me.
- throwthere 5y agoThank you! I'll take a look.
- swah 5y agoNestJS was the promising one a year ago...
- worstestes 5y agoIs it not so anymore? Just started learning the framework last week and have been enjoying it so far