Express - Node.js web application framework

特点

Express 的路由方式

Express basic routing

app.get('/', function (req, res) {
  res.send('Hello World!')
})
app.get('/', function (req, res) {
  res.send('Hello World!')
})
app.put('/user', function (req, res) {
  res.send('Got a PUT request at /user')
})
app.delete('/user', function (req, res) {
  res.send('Got a DELETE request at /user')
})

处理静态文件

Serving static files in Express

app.use(express.static('public'))
app.use(express.static('public'))
app.use(express.static('files'))
app.use('/static', express.static('public'))
const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'public')))