N
N
narem2019-09-26 20:07:44
Node.js
narem, 2019-09-26 20:07:44

How to use restructuring?

I watch the lesson, the person does the restructuring like this

app.post('/create',(request, response) => {
  const {title, body} = request.body;
  Post.create({
    title: title,
    body: body
  }).then(post => console.log(post._id))
  
  response.redirect('/');
});

i.e. he enters
const {title, body} = request.body;
to restructure the data.
But my console gives me an error
const {title, body} = request.body; SyntaxError: Unexpected token {
and the arrow underlines the first parenthesis. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question