微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

您在哪里可以看到 POST 请求 NodeJS express 服务器中的 console.log 语句?

如何解决您在哪里可以看到 POST 请求 NodeJS express 服务器中的 console.log 语句?

我在 NodeJS 中有一个快速服务器。它有一个带有 console.logs 的 POST 请求。在哪里可以找到 console.logs?

const express = require('express');
const cors = require('cors');
const app = express();

app.use(cors());
app.use(express.json());

const PORT = 5000;

app.get('/',(req,res) => {
    console.log("this appears in the browser");
});

app.post('/login',res) => {
    console.log("where do I see this text??");
});

app.listen(PORT,'0.0.0.0',function() {
    console.log("Server started (this text appears in the terminal)");
});

我正在从命令提示符运行服务器。不在请求中的 console.logs 出现在其中。 POST请求函数中的console.logs出现在哪里?我之所以这么问是因为我想看看更复杂的 POST 请求中的逻辑发生了什么。

解决方法

当您直接从 cmd 运行 Node.js 服务器时,它应该启动服务器并侦听指定的端口。现在,当你开始点击路由时,所有的 console.log o/p 都指向终端窗口,而不是浏览器控制台窗口。检查图像以供参考。

enter image description here

,

它将出现在您让服务器运行的同一个终端中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。