Please enable JavaScript.
Coggle requires JavaScript to display documents.
MIDDLEWARES - Coggle Diagram
MIDDLEWARES
BASICS
Server.js
Creating
const logger =
(req, res, next) =>
{..}
clo(req.originalUrl)
next()
Using
In-App
app.use(logger)
In-Routes
router.use(logger)
One-route
app.get(..)
path
...middlewares...
func(req,res)
Runs
Only-For-routes
After-use-stmt
ROUTER.PARAM
Url
Has
Specific-Param
Runs
Before
Actual
Router-Mthd
Pass-Control
next()
Add-Data
To-Request
req.newField
Use
router.param('id', func)
func
req.user =
userFromDb[value]
args
value
Of-Id-Param
req,res,next
next()
QUERY
Params
Parse
Access-As
req.query.fieldName
BUILT-IN
Serve-Static
Files
Create
public/
In-Server.js
app.use(express.static('public'))
Parsing
Form/JSON
Data
Accessing
Post-Req-Data
app.use(..)
express.urlencoded(..)
{extended: true}
extended
True
Uses-qs-lib
False
Uses-builtin-lib
In-routes
In-post
const name =
req.body.firstName
Json-Data
app.use(..)
express.json()
Runs
When
Content-Type
application/json