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:
But it doesn't using Forms:
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})
}
}