Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

javascript - express PUT request is timing out

I am trying to update a file in my Mongo DB via a form using a PUT request in the browser and using Mongoose findByIdAndUpdate. It executes and the file updates in the database. However, the PUT request keeps executing indefinitely and is causing a timeout error.

I am new to Node/JS - and so apologies if this is a basic question.

app.put('/essays/:id', async(req, res) => {
  const { id } = req.params;
  const essay = await Essays.findByIdAndUpdate(id, {...req.body.essay });
  console.log("updated")
})

Browser:

<form action="/essays/<%=essay._id%>?_method=PUT" method="POST" id="myForm">
        <input type="hidden" id="essayBodyNew" name="essay[essayBody]" value=> </form>

Here is my console:

PUT /essays/600db52af8c50e195c159383?_method=PUT - - - - ms

It's also timing out when I make PUT requests on Postman.

question from:https://stackoverflow.com/questions/65874237/express-put-request-is-timing-out

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

call res.end('some message') after console statement to close request


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...