jsonrestexpresspostmanhttp-status-code-400

Postman Bad Request Error When There Is No Syntax Error


I have been trying to send a post request to my server on Postman. But I have been getting the 400 Bad Request Error. The description of the error says "The request cannot be fulfilled due to bad syntax." However, my JSON body does not have any incorrect syntax, and other similar questions do not cover this error occurring when the syntax is correct.

enter image description here

This is what the headers look like:

enter image description here

What could possibly be the reason behind this happening?

Edit: This is the code of the server side:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const articleRoutes = express.Router();
const PORT = 4000;

let Article = require('./article.model');

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

mongoose.connect('mongodb://127.0.0.1:27017/articles', { useNewUrlParser: true, useUnifiedTopology: true });
const connection = mongoose.connection;

connection.once('open', function() {
    console.log("MongoDB database connection established successfully");
});

articleRoutes.route("/content-management-system/add").post((req, res) => {
    let article = new Article(req.body);
    console.log(article);
    article.save()
        .then(article => {
            res.status(200).json({'article': 'article saved successfully'});
        })
        .catch(err => {
            res.status(400).send('adding new article failed');
        });
});

app.use('/', articleRoutes);

app.listen(PORT, function() {
    console.log("Server is running on Port: " + PORT);
});

Solution

  • The issue was in my mongoose.connect line where I put articles when it should be article after mongodb://127.0.0.1:27017/.