DEV Community

Discussion on: How I structure my REST APIs

Collapse
 
matt123miller profile image
Matt Miller

I recently started on a little TypeScript Express starter project and I'm enjoying it so far. I'm also looking to add TypeORM to my setup! I'm trying to create a super lean setup to replace Adonis.js as the maintainer has refused to adopt TS.

I was hoping you could answer some questions though.

I was trying to find a convenient way that to add all the routes and I struggled with that (though I just started learning TS). Looking at your setup, does each module router create a new Express router? And those are then exported and added to the Express instance via the app.use('route group', module_router) ?? I never knew it accepted instances of a router.

Collapse
 
larswaechter profile image
Lars Wächter

Yeah, each router in the /modules/ folder creates a new instance of the express router and those instances are exported to server.ts

This might be interesting for you: expressjs.com/en/4x/api.html#router