Building a Website with Sarunyhot Suvannachoti (Kao) Software Engineer @ Jitta.com Express.js
What is express? • Node.js web application framework • Inspired by Sinatra • Asynchronous
Routing
Routing
Route handlers
Response methods Method Description res.download() Prompt a file to be downloaded. res.end() End the response process. res.json() Send a JSON response. res.jsonp() Send a JSON response with JSONP support. res.redirect() Redirect a request. res.render() Render a view template. res.send() Send a response of various types. res.sendFile Send a file as an octet stream. res.sendStatus() Set the response status code and send its string representation as the response body.
Chainable route
Middleware Browser Request app.get(‘/user’) app.post(‘/blog’) app.delete(‘/book’)
Middleware Browser Request app.get(‘/user’) middleware app.post(‘/blog’) app.delete(‘/book’)
Middleware Browser Request app.get(‘/user’) checkAdmin app.post(‘/blog’) app.delete(‘/book’) logRequest checkLogin checkAccess
Middleware

Build web application with express