What is Routes handler in Express JS

Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, PUT, DELETE).
Each route can have one or more handler functions, which are executed when the route is matched.
Route definition takes the following structure:


In above syntax app is an instance of express.
METHOD is an HTTP request method (GET,POST,PUT,DELETE), in lowercase.
PATH is a path which you are calling on the server.
HANDLER is the function executed when the route is matched.

Above example given by express js instance same thing you can do with the help of router method.
When you are going to use router method then you can separate out all your routes in one file and then import that in same index file and this is just for code visibility.

News Reporter

Leave a Reply

Your email address will not be published. Required fields are marked *