Error sending mongodb information on Node

Asked

Viewed 20 times

0

Hello guys I’m having the following problem, my Node is accusing error:

ReferenceError: Cannot access 'user' before initialization

I am working with Schema user record in the case below I show a POST:

app.post('/register', (req,res) =>{
    

    const {nomecompleto,email,password} = req.body
    const user = new user({nomecompleto,email,password}) 



})

I’m importing the model user file that looked like this const User = Require('./model/user')

I have tried several actions to correct more it still gives error on line 36 in the case when we put the const

1 answer

0

As you said in the question, if you did:

const User = require('./model/user')

When creating a user instance, you should do:

const user = new User({nomecompleto,email,password})

So you’ll probably get the expected result.

The difference between my code and yours is that I’m instantiating an object "User", the same I did import with command require.

In your code you’re using with the letter u minuscule.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.