Skip to content

Better way to write your router file #29

Description

@FarahZaqout

router.get('/', getHomePage);

it's much better for readability to cluster your route handling based on the route requested rather than having what you are doing now.

router
 .route('/my-route')
 .get(callBack)
 .post(callBack)

and so on.

I would also suggest separating your router from the controllers, and separating your API router from your client (views) router.

you could have a routers directory just like you have one for the controllers and export any routers you have from the index of that directory.

in the server, you would require the clientRouter and the apiRouter, where you can do app.use(clientRouter) and app.use('/api', apiRouter)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions