skip to Main Content

when i try to default register a new user then i can’t register it on website ,and it shows internal server error in and failed to load resource error in console .

[enter image description here](https://i.stack.imgur.com/CFa17.png)[[[enter image description here](https://i.stack.imgur.com/QrSB2.png)](https://i.stack.imgur.com/CWlKT.png)](https://i.stack.imgur.com/OMAnc.png) please help ...


I tried everything ,double checked the codes ,still could solve the error,

I think the the fault lies somewhere in the backend integration with cloudinary I have shared the usermodel and usercontroller.

edit 1:
user model 

    const mongoose = require("mongoose");
    const validator = require("validator");
    const bcrypt = require("bcryptjs");
    const jwt = require("jsonwebtoken");
    const crypto = require("crypto");
    
    const userSchema = new mongoose.Schema({
      name: {
        type: String,
        required: [true, "Please Enter Your Name"],
        maxLength: [30, "Name cannot exceed 30 characters"],
        minLength: [4, "Name should have more than 4 characters"],
      },
      email: {
        type: String,
        required: [true, "Please Enter Your Email"],
        unique: true,
        validate: [validator.isEmail, "Please Enter a valid Email"],
      },
      password: {
        type: String,
        required: [true, "Please Enter Your Password"],
        minLength: [8, "Password should be greater than 8 characters"],
        select: false,
      },
      avatar: {
        public_id: {
          type: String,
          required: true,
        },
        url: {
          type: String,
          required: true,
        },
      },
      role: {
        type: String,
        default: "user",
      },
      createdAt: {
        type: Date,
        default: Date.now,
      },
    
      resetPasswordToken: String,
      resetPasswordExpire: Date,
    });
    
    userSchema.pre("save", async function (next) {
      if (!this.isModified("password")) {
        next();
      }
    
      this.password = await bcrypt.hash(this.password, 10);
    });

when i did try catch err call then this error was in the console log      

error: Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
at new NodeError (node:internal/errors:399:5)
at internalConnectMultiple (node:net:1099:20)
at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: ‘ERR_SOCKET_CONNECTION_TIMEOUT’
}

2

Answers


  1. Chosen as BEST ANSWER

    edit - the actual error was -error: Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout at new NodeError (node:internal/errors:399:5) at internalConnectMultiple (node:net:1099:20) at Timeout.internalConnectMultipleTimeout (node:net:1638:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { code: 'ERR_SOCKET_CONNECTION_TIMEOUT' }

    node v20.2 is not compatible with uploading on cloudinary , so i upgraded it to 20.4 and it worked.


  2. enter image description hereenter image description here

    you expected "avatar" key in body here because program trying to fetch data from req.body.avatar but in the postman request payload you didn’t give avatar key in body. Probably error causes from that reason.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search