Duas要求使用Dentro de umúnico中间件

时间:2019-12-25 19:04:26

标签: javascript node.js express backend

épossívelmandar 需要终止服务不能使用中间件,而不能使用 nome e email 来代替com对象nome “注册” ,quero salvar os dois dentro do objeto comúnico中间件。

const express = require('express')

const server = express()

server.use(express.json())

const register = {
  names: [], emails: []
}

server.post('/users', (req, res) => {

  const { name } = req.body
  //console.log(name);
  register.names.push( name )
  return res.json( register.names )

  const { email } = req.body
  register.emails.push( email )
  return res.json( register.emails )

})

server.post('/users_1', (req, res) => {

  //console.log(email);

})

server.delete('/users/:index', (req, res) => {

  const { index } = req.params
  register.names.splice(index, 1)
  return res.json( register.names )

})

server.get('/users', (req, res) => {

  return res.json(register)

})

server.listen(3000)

通过模拟:)

0 个答案:

没有答案