Build web application with express

11
Building a Website with Sarunyhot Suvannachoti (Kao) Software Engineer @ Jitta.com Express.js

Transcript of Build web application with express

Page 1: Build web application with express

Building a Website with

Sarunyhot Suvannachoti (Kao) Software Engineer @ Jitta.com

Express.js

Page 2: Build web application with express

What is express?• Node.js web application framework

• Inspired by Sinatra

• Asynchronous

Page 3: Build web application with express

Routing

Page 4: Build web application with express

Routing

Page 5: Build web application with express

Route handlers

Page 6: Build web application with express

Response methods

Method Descriptionres.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.

Page 7: Build web application with express

Chainable route

Page 8: Build web application with express

Middleware

Browser

Request

app.get(‘/user’)

app.post(‘/blog’)

app.delete(‘/book’)

Page 9: Build web application with express

Middleware

Browser

Requestapp.get(‘/user’)

middleware app.post(‘/blog’)

app.delete(‘/book’)

Page 10: Build web application with express

Middleware

Browser

Requestapp.get(‘/user’)

checkAdmin

app.post(‘/blog’)

app.delete(‘/book’)

logRequest

checkLogin

checkAccess

Page 11: Build web application with express

Middleware