I am running a backend code written on Node.js for my application. When I host my backend on a port, I am able to get the API response to my client side but outputs that should be displayed in console log(in Node) are not being displayed. I am assuming that when I run this code on my localhost port the entire code should be executed thus resulting in console log outputs (eg: "DB connected" should be displayed in console log). But this is not happening. Only the post request console log O/P is being displayed(i.e "response sent"). Why is this happening?
Note: The post request O/P is displayed only when I post to the backend. It is not being displayed by default which is the expected behaviour.
import express from "express";
import mongoose from "mongoose";
import cors from "cors";
import DB from "./env";
const app = express();
// DB connection
mongoose.connect(DB,{})
.then(() => {console.log("DB connected")})
.catch((error) => {error});
//middlewares
app.use(express.json({}));
app.use(cors({
origin:["http://localhost:3000"],
}));
//the actual backend response from server
app.post("/" , (req,res) => {
console.log("response sent");
//console.log(req.body.email);
//console.log(req.body);
res.end("backnd working");
})
//listen on port 8000
app.listen(8000);