req.body is undefined in a post request

I'm trying to print to the console the content of the request's body inside a post function as follows:

export const createOffering = async (req, res) => {
const offering = req.body;
const newOffering = new Offering(offering);
    res.status(409).json({message: error.message})


However, the console prints "undefined"

Here is the code for my index.js

import express from "express";
import mongoose from "mongoose";
import cors from "cors";
import bodyParser from "body-parser";
import offeringsRoutes from './routes/offerings.js'

const app = express();

app.use('/offerings', offeringsRoutes);

app.use(express.urlencoded({ limit: '25mb', extended: true }));
app.use(express.json({ limit: '25mb' }));

Read more here:

Content Attribution

This content was originally published by PINK at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: