btror
btror

Reputation: 125

Where do you see console.log statements inside a POST request NodeJS express server?

I have an express server in NodeJS. It has a POST request with console.logs inside of it. Where Can I find the 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', (req, 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)");
});

I'm running the server from Command Prompt. console.logs that aren't within a request appear in it. Where do the console.logs in the POST request function appear? I ask because I would like to see what's going on with the logic inside a more sophisticated POST request.

Upvotes: 1

Views: 2825

Answers (2)

Eduardo Matos
Eduardo Matos

Reputation: 1

It will appear in the same terminal that you put the server to run.

Upvotes: 0

Apoorva Chikara
Apoorva Chikara

Reputation: 8773

When you run the Node.js server directly from cmd, it should start the server and listening to the port specified. Now, when you start to hit the route/s all the console.log o/p to the terminal window not to the browser console window. Check the image for reference.

enter image description here

Upvotes: 2

Related Questions