Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
{error:{ }} is being returned in express js backend (mongodb)

I'm trying to POST Data to Mongo DB Using Express Js.

I'm new to express just learned for a backend server

This is my app.js

const express = require("express");
const mongoose = require("mongoose");
require("dotenv/config")
const User = require("./model/user.js")

let app = express();
app.use(express.json())
app.get("/", (req,res) => {
    res.send("On Home!")
});
app.post("/register", async (req,res) => {
    try {
        const myUser = new User(req.body);
        await myUser.save();
        res.send(myUser);
    } catch (err){
        res.send({error : err});
    }
});
mongoose.connect(process.env.DB_URI,(req,res) => {
    console.log("Connected to Database!")
});
app.listen("5000" , () =>{
    console.log("Listening on localhost 5000")
})


My user.js

const mongoose = require("mongoose");

const User = mongoose.Schema({
name: {
    type: String,
    required: true,
},
email:{
    type:String,
    required: true,
},
pass:{
    type: String,
    required: true,
}
});

module.exports = mongoose.model("user",User)

My Response Is

My Response

(I'm Using Postman to test)

Thank You For Your Support

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use body-parser, add this to your code:

var bodyParser = require('body-parser');
app.use(bodyParser.json());
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!