Logo

dev-resources.site

for different kinds of informations.

How to add multiple routers in a node application without using app.use() for each router ?

Published at
8/23/2021
Categories
node
webdev
approuter
Author
dibyojyoti
Categories
3 categories in total
node
open
webdev
open
approuter
open
Author
10 person written this
dibyojyoti
open
How to add multiple routers in a node application without using app.use() for each router ?

In node.js, when we have multiple Express.Router written in a separate file to enhance modularization we need to import each route file into the application server file and add lots of app.use() statements. Now, if we add a new router we need to remember to add that too in the file where the application server is written.

Let's assume there is a routes folder where the routes are defined for user and order handling separately in separate files. in application server file we need to use app.use two times. imagine if our routers increase the solution will not be very good.

we can add a small code snippet in our application server JS file that will automatically import and add all of the routes in the application.
In this blog I gave an example of the initial approach and also showed how that code snippet looks like.

approuter Article's
23 articles in total
Favicon
Show a loading screen when changing pages in Next.js App router
Favicon
Learning Next.js 13 App Router: A Comprehensive Guide 🚀
Favicon
Guide to build a modern Web App using Next.js 14 (App Router), Fully authentication (NextAuth), Theming and i18n
Favicon
A practical Guide - Migrating to Next.js App Router
Favicon
Adding Chat Functionality To Your Next.Js Project With Firebase
Favicon
Spicing Up Your Next.Js Projects With 3D: What Are Your Options?
Favicon
No More Pages
Favicon
How To Create A Basic Infinity Canvas For Your Next.Js Project
Favicon
How To Implement Text-To-Speech Functionality For BlockNote In Next.Js
Favicon
How To Add Drag-And-Drop Functionality With Editable Draggable Items In Next.js
Favicon
Adding Drag And Drop Functionality In Your Next.Js Project Without A Library
Favicon
Creating NPM Packages in Next.Js for Next.Js
Favicon
Using Firebase To Store Folders and BlockNote Documents In Next.Js
Favicon
An Alternative To Editor.js: BlockNote For React
Favicon
How To Add Editor.Js To Your Next.Js Code
Favicon
How To Use The Quill Rich Text Editor in Your Next.Js App Router Project
Favicon
Simple NextJS GraphQL client
Favicon
Implementing Internationalization (i18n) in Next.js 14 using App Router
Favicon
Web Streams API in Action: Delivering 6000+ Log Lines Concurrently Across 20 Tabs
Favicon
How to use React-Toastify with Next.js App router
Favicon
NextAuth - Implementando "Custom Login Pages" com "Credentials Sign in" utilizando App Router
Favicon
The origin of App Router - A Next.Js Rewind
Favicon
How to add multiple routers in a node application without using app.use() for each router ?

Featured ones: