How to resolve 400 Bad Request errors on POST request for a sample MERN application?

Hi, I have started to work on the MERN stack application where I have created the Node JS-related files and connected the same to MongoDB. I have created a POST call that sends the JSON to the DB. I tried to test the API using postman but not sure what’s wrong, I have checked multiple times, the API throws bad requests. Please find attached a screenshot as a reference to the problem.

However, I am getting a successful response for GET requests on the same server.

Here is the code:

app.js

// Imports
require('dotenv').config()
const mongoose = require('mongoose');
const express = require('express');
const app = express();
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const authRoutes = require("./routes/auth");

// DB Connection
mongoose.connect(process.env.DATABASE, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true
}).then(() => {
    console.log("DB CONNECTED!");
})


// Middlewares
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());

// Routes
app.use("/api", authRoutes)


// Port
const port = process.env.PORT || 3000;

// Start Server Message
app.listen(port, () => {
    console.log(`App is running at ${port}`);
});

auth.js

var express = require('express')
var app = express();
const router = express.Router()
const { signout, signup } = require("../controllers/authController")

router.post("/signup", signup);
router.get("/signout", signout);

module.exports = router;

authController.js

const User = require("../models/user");

exports.signup = (req, res) => {
    const user = new User(req.body);
    user.save((err, user) => {
        if (err) {
            return res.status(400).json({
                err: "USER NOT SAVED!"
            })
        }
        res.json(user);
    })
  } 

exports.signout = (req, res) => {
    res.json({
        message: "User signout"
    })
}

A similar problem was recently posted on Stackoverflow

Application: Postman Desktop for Apple Silicon
Version: v9.13.0

Any help on this is much appreciated. Thanks.

Strangely enough, it works perfectly fine with the “Postman extension” for chrome that is deprecated.

@red_devil Welcome to the community :partying_face:

Oh sorry to hear that. Did you checked the header values?

Yes, I did. Here is a screenshot from Postman Desktop Client.

Same request on Postman Chrome Extension.