News for hackers. Stuff that matters.

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?
( 6 comments | 5 points | on HN )
Re:Ask HN: Best way to structure/architect an API with Expre... by bacbilla on Friday September 17, 2021 @04:55AM (#28562893)
I honestly recommend 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.

Re:Ask HN: Best way to structure/architect an API with Expre... by throwthere on Friday September 17, 2021 @08:06AM (#28564466)
Thank you! I'll take a look.
Re:Ask HN: Best way to structure/architect an API with Expre... by gitgud on Thursday September 16, 2021 @11:56PM (#28561036)
There'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

Re:Ask HN: Best way to structure/architect an API with Expre... by riemann on Thursday September 16, 2021 @09:51PM (#28560281)
Frameworks 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.
Re:Ask HN: Best way to structure/architect an API with Expre... by swah on Friday September 17, 2021 @08:11AM (#28564506)
NestJS was the promising one a year ago...
Re:Ask HN: Best way to structure/architect an API with Expre... by worstestes on Friday September 17, 2021 @12:04PM (#28567085)
Is it not so anymore? Just started learning the framework last week and have been enjoying it so far