简体   繁体   English

如何诊断/调试 nodejs/expressjs 的 500 内部服务器错误?

[英]How do I diagnose/debug a 500 internal server error for nodejs/expressjs?

So to post data from HTML form to express js server I keep getting and Internal Server Error 500. It doesn't say why, just prints POST /routeitisreaching 500因此,要从 HTML 表单发布数据以表达 js 服务器,我不断收到内部服务器错误 500。它没有说明原因,只是打印 POST /routeitisreaching 500

How do I go about figuring out what is causing the issue?我该如何找出导致问题的原因? It is not even hitting that route because I have a console.log in place as the route code executes and that doesn't get run.它甚至没有到达该路线,因为在路线代码执行时我有一个 console.log 并且没有运行。

This is from the issue I posted Internal Error 500 at POST request Express JS and Formidable这是来自我在 POST 请求 Express JS 和 Formidable 上发布的内部错误 500的问题

Is there a log file getting saved somewhere in windows where I can see the details of what is happening from form submission to backend?是否有日志文件保存在 Windows 中的某处,我可以在其中查看从表单提交到后端发生的情况的详细信息? I am really stuck need help.我真的卡住了需要帮助。

Maybe it will be helpful https://expressjs.com/en/guide/debugging.html也许它会有所帮助https://expressjs.com/en/guide/debugging.html

You can also try commenting slices of code and check if server responds.您还可以尝试注释代码片段并检查服务器是否响应。

Well, I encountered same issue and the Terminal does not giving any error message.So here is what we can do好吧,我遇到了同样的问题,终端没有给出任何错误信息。所以这是我们可以做的

At the end of your app.js(main file) write following code在 app.js(主文件)的末尾写下以下代码

app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  console.error(err);
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: err
  });
});

and then create a new file error.ejs under views folder.然后在views文件夹下创建一个新文件error.ejs。 In /views/error.ejs write在 /views/error.ejs 中写入

There was some error
<pre>
<%= message; %>
<br>
<br>
<br>
<%= error; %>

And you should now see more details about your error.您现在应该会看到有关您的错误的更多详细信息。 I helped me debugging 500 errors a lot.我帮我调试了很多 500 个错误。 Hopefully this help other too希望这也能帮助其他人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM