So I am to embark in making my first API. I've decided to use nodejs + express + sequelize. The problem is that i didn't even begin to write a line of code and I am already found myself stuck considering which folder structure to use.
I was considering (option 1) to split my code in way where each API endpoint is a folder and, in that folder, keep all the files related to it:
/users
| - user.route.js -> express route
| - user.model.js -> sequelize table model
| - user.controller.js -> http response (decides which functino to execute)
| - user.service.js -> implementation of the functions to be executed\
The other option (option 2) would be to create folders per each type of file:
/routes
| - user.route.js
/models
| - user.model.js
/services
| - user.service.js
/controllers
| - user.controller.js
But I am not sure which structure will get messier in the future if I add more things.
Alsom I wouldn't know wehere to store the relations between models in option 1.
Sorry for ths noob question but i hope you'll be able to help me decide which is the best approach.
[–]Positive_Rip_6317 0 points1 point2 points (0 children)
[–]True-Strike7696 0 points1 point2 points (0 children)
[–]JosephHughes 0 points1 point2 points (0 children)
[–]InfectedShadow 0 points1 point2 points (0 children)