[Fixed] how to resolve body-parser module disabled looking in node app?

Issue

My API doesn’t work well and I’ve noticed that the body-parser module seems somehow disabled and I didn’t find anything about it, please see the attached photo. Is there any solution?

vscode screenshot

var express = require("express");
var bodyParser = require('body-parser');
var bcrypt = require('bcrypt');
var url = require('url');
var querystring = require('querystring');
var cors = require('cors');
var MongoClient = require('mongodb').MongoClient
var nodemailer = require("nodemailer");
var Users = require("./models/Users");
var mongoose = require('mongoose');
var app = express();

app.use(bodyParser.json());
app.use(cors());
app.use(bodyParser.urlencoded({ extended:  true }));
app.use(bodyParser.json());


var mongoDB = 'mongodb://localhost:27017/usersDB';
mongoose.connect(mongoDB, {useNewUrlParser: true, useUnifiedTopology: true});



app.get('/', (req, res) => {
  res.send('Hello World!')
});

Solution

using this instead of pody-parser resolved the problem:

const express = require('express');

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

Leave a Reply

(*) Required, Your email will not be published