Your express middleware and router setup looks great! One recommendation that I would make it to consider adding an API level router abstraction to prevent having to continually add routers in your server.js file. There are of course a hundred different ways to structure an express application, but at least for me, I've come to enjoy letting my server.js primarily contain standard express setup boilerplate code and create an extra file that contains the main API router setup. Here is an example of what I mean.
Your express middleware and router setup looks great! One recommendation that I would make it to consider adding an API level router abstraction to prevent having to continually add routers in your
server.js
file. There are of course a hundred different ways to structure an express application, but at least for me, I've come to enjoy letting myserver.js
primarily contain standard express setup boilerplate code and create an extra file that contains the main API router setup. Here is an example of what I mean.server.js
./api/index.js
Now as my API grows over time I can leave my
server.js
alone and just modify./api/index.js
.Again, this is not necessarily a best practice but rather just a recommendation based upon how I like to do things in case this resonates with you.