MERN Stack Tutorial - Book Store Project

When post request ran in Postman an instance is created in the DB, but no data filed values are sent

import express from "express";
import {PORT, mongoDBURL} from "./config.js";
import mongoose from "mongoose";
import {Book} from "./models/bookModel.js";

const app = express();


// Create HTTP Route requests
app.get('/', (request, response)=>{
    return response.status(234).send("Welcome to MERN Stack Tutorial");

//--> Route to save a new book: this is an async process"/books", async(request, response)=>{
    try{ //"try validating the input"
            !request.body.title ||
            ! ||
          ) {
            return response.status(400).send({
                message: "Send all required fields: title, author, publishYear",
          const newBook = {
            title: request.body.title,
            publishYear: request.body.publishYear

          const book = await Book.create(newBook);
          return response.status(201).send(book);
    } catch(error){
        response.status(500).send({message: error.message});

    .then(() => {
        console.log("App connected to database");
        app.listen(PORT, ()=>{
            console.log(`App is listening to port: ${PORT}`);
    });`Preformatted text`
  • what do you see in this console log

or perhaps you can also try looin onto their “save” method instead, this article here shows how The `create()` Function in Mongoose - Mastering JS

happy coding :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.