ExpressJS — Clean Routing

--

There are at least 3 ways to route using ExpressJS.

First and the most common is to have everything in one file. Then you can have it in two separate files, server and routes, or have a route file for each page, if your pages don’t need to interact with themselves this will be the cleaner way of defining routes.

Lets see what which one looks like.

Normal, single file routing.

Routing from a separate file:

Routes on each file:

So as we can see each method requires a little difference when setting up the server. This makes the code more readable there fore easier to have a team work with it.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response