Express Js Recap

 Adding Middleware













App.use()

next => We use next to allow the middleware to travel to the next middleware, if no next than it will keep on spinning.

 To complete the request end it with res

Body Parser zeng

 If you don't use body-parser than we won't be able to parse the body from 

Using Middleware

First we will go to localhoste/add-product than after submission of form present there it will go to /product page and will redirect to home. We don't need to create route now like node js

However in the above it will also work for get reqeust we will limit it in the next ss


Express Router

Add a folder name route

Than add a file named admin.js in it

 Here we are exporting the router and this router is a object which containe /add-product and /product.

and best part is that it is a valid middleware function so we import it with app.use() and it will automatically get added.


ORDER MATTERS

If we use shopRouter above adminRouter it will never reach shoprouter as it can be only acccesed by admin Router 

positon matters when importing if we use app.get but not matter if we use app.use as it has app.send and also route matchs (sai lom if needed)

404 page


 Filtering Paths


 In this both have /admin ad the begginning than we can remove it and add /admin at index instead

 

 

 

Creating HTML 


 Servin html


 

nn

Comments

Popular posts from this blog

Form Part 2

Event mini project by Thapa#33

De-mystifying 'this' keyword of Javascript