0

I've tried it with Postman too and it does the same thing. I was following a tutorial and ran into this problem, which the creator didn't have. I copied and pasted (After error) his same working folder and the same thing:

It works with JSON: enter image description here But it doesn't using Forms: enter image description here

I used to think I will never use one of this pages, but now I'm introducing myself to programming, I know I will use it thousands of times. I have like 4 hours straight looking to solve this problem. Please!

This is my schema:

import mongoose from "mongoose";

const postSchema = new mongoose.Schema({
    title: {
        type: "String",
        required: true,
        trim: true,
    },
    description: {
        type: "String",
        required: true,
        trim: true,
    },
    image: {
        url: "String",
        public_id: "String",
    }
})

export default mongoose.model('Post', postSchema)

And this is my createPost:

const createPost = async (req, res) => {
    try {
        const { title, description } = req.body;

        const newPost = new Post({ title, description })
        
        await newPost.save()
        
        return res.json(newPost)
    } catch (error) {
        res.status(500).json({error: error.message})
    }
}

lpizzinidev
  • 12,741
  • 2
  • 10
  • 29
Gorgi-San
  • 9
  • 2
  • 1
    Have you attempted to contact the tutorial author and ask that person for assistance befor asking a bunch of strangers who don't know anything about the tutorial? It seems they produced the error. Alternatively, you should investigate what a URL Encoded Form is and how to process it with express. [This answer](https://stackoverflow.com/questions/23259168/what-are-express-json-and-express-urlencoded) should get you started. – Randy Casburn Dec 30 '22 at 01:46

0 Answers0