Are there naming conventions on router files?
Nothing required, like many other things in Express, route files are flexible, but in terms of community, there has been a certain agreement on naming conventions, to pair the file name with the route, and some places do ask to write the word route as part of the name. ie
monsterRoutes.js but again, most commonly we can see simply
monsters.js related to the
/monsters route. Another thing to have in mind is that having a
router.js file that handles all the route connections is also common, for example the following file map:
mainApplicationDirectory/ | | | __ app.js __ router.js | | __ routes/ | | __ monsters.js __ animals.js __ fruits.js
We can see that now we could also have a directory of routes where each route handler file exists and are connected to our app through a main
router.js file. This sort of system is commonly seen when there is a hight complexity in our routes that is better to have a middleware to handle routes instead of implementing
app.use('/route', routeHandler) inside of app.