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

189
Views
When I send a request, I always get an error. React and MongoDB

I am new to IT, I started learning React and JS through video courses. When creating a site for a video course, I encountered a number of errors: when I try to send a request wrapped in a try catch, I always get an error. I don't understand why this is happening, please help.

index.js

const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const authRoute = require("./routes/auth");


dotenv.config();

mongoose
  .connect(process.env.URL_MONGO, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(() => console.log("Successfully connected"))
  .catch((err) => {
    console.error(err);
  });

app.use(express.json());

app.use("/api/auth", authRoute);


app.listen(8800, () => {
  console.log("Server is running!");
});

User.js

const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema(
  {
    username: { type: String, required: true, unique: true },
    email: { type: String, required: true, unique: true },
    password: { type: String, required: true },
    profilePic: { type: String, defaut: "" },
    isAdmin: { type: Boolean, default: false },
  },
  { timestamps: true }
  
);

module.exports = mongoose.model("User", UserSchema);

auth.js

const router = require("express").Router();
const User = require("../models/User");


router.post("/registration", async (req, res) => {
  const newUser = new User({
    username: req.body.username,
    email: req.body.email,
    password: req.body.password,
  })

  try {
    const user = await newUser.save();
    res.status(201).json(user);
  } catch (err) {
    res.status(500).json(err);
  }
});

module.exports = router;

Register request

Second part Postman

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

0

For what I see on your img, you're doing a Netflix clone as I'm doing.

I can see that your request on postman is:

{
 "username" = "eeqeqeqw",
 "email": "nova@gmail.com",
 "password":"2221"
}

So when working with objects, the values are asigned with ":" instead of "=" symbol.

Try to do the same request this way:

{
 "username": "eeqeqeqw",
 "email": "nova@gmail.com",
 "password":"2221"
}
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!