您在哪里可以看到 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

,

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