(Is it recommended to do so)
I feel the code for the routes could be easier to read and debug are further modularised. Is it a good practice to do so?
We have the usual code
In app.js
var users = require('./routes/users');
app.use('/users', users);
In the users.js
file I have the code for these routes:
/user
/user/bar
/user/42
/user/42/baz
/user/42/baz/123
I gave code for get
, post
, put
and use
. And I feel the file is too messy.
Is it recommended to split the ./routes/users.js
further and is there a design pattern for it?
Edit as per requested though this was a generic question
var express = require("express");
var marked = require("marked");
var OfflineMediaModel = require("../models/offlineMediaModel");
const offlineMediaRouter = express.Router();
var fs = require("fs");
var md = require("node-markdown").Markdown;
var path = require("path");
var config = require("../config");
// Middleware
offlineMediaRouter.use("/", function(req, res, next) {});
offlineMediaRouter.use("/podcasts/test", (req, res, next) => {});
offlineMediaRouter
.post("/podcasts/test", function(req, res) {}) /// this is the only post
.get("/", function(req, res) {})
.get("/:podcast", function(req, res) {})
.use("/:podcast/:episode", function(req, res, next) {})
.get("/:podcast/:episode", function(req, res) {});
module.exports = offlineMediaRouter;
I'm wondering in much bigger projects that that, would further modularising that code be a good idea or is it not advised to do so? Or should the code within the routes methods