Getting Null values from req.body

Issue"/Signup", (req, res, next) => {
  try {
      'SELECT email FROM auth WHERE email ="' + + '"',
      async (err, result) => {
        if (err) return err;
        if (result.length === 0) {
          const redirectUrl = req.session.returnTo || "/home";
          delete req.session.returnTo;
          // const salt =  bcrypt.genSaltSync(10);
          // const hash =  bcrypt.hashSync(req.body.pass, salt);
          const users = {
            firstname: req.body.firstname,
            lastname: req.body.lastname,
            pass: req.body.p
            address: req.body.address,
            province: req.body.province,
            img: req.body.img
          const sql = "INSERT INTO auth SET ?";
          await db.query(sql, [users], (err, rows) => {
            if (err) res.send(err);
            else req.flash("success", "Successfully registered!");
            return console.log('complete');
        } else if (result[0].email.length > 0) {
          req.flash("error", "The Entered email already exsists");
          return res.redirect("/Signup");
  } catch (e) {


This is my post route for signup. but it is not geeting the value from req.body.I have also used bodyparser.It is showing this message.


If there something wrong with my code.PLease tell me.

Thank you.


There are 2 concerns here.

  1. check wether you are using bodyparser or not, if not using, please install and use as here.

var bodyParser = require('body-parser')
var app = express()

app.use(bodyParser.urlencoded({ extended: false }))

  1. In the postman, below the body tab, click on raw and select type as json

and submit the request.

Hope this helps!

Answered By – sachin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published