how to add user’s information in mongoose database?


i have a registration form in .jade format

form(method='post', action='/users/register', enctype='multipart/form-data')
          label Name
          input.form-control(name='name', type='text', placeholder='Enter Name' required)
          label Email
          input.form-control(name='email', type='email', placeholder='Enter Email' required)
          label Username
          input.form-control(name='username', type='text', placeholder='Usernamee' required)
          label Password
          input.form-control(name='password', type='password', placeholder='Enter Password' required)
          label Password
          input.form-control(name='password2', type='password', placeholder='Confirm Password' required)
          label Profile Image
          input.form-control(name='profileimage', type='file')
      input.btn.btn-default(name='submit', type='submit', values='Register') 

and this is how i’m creating a new user and trying to add them to the database but the data is not being added into the database. The problem is it’s not taking values from the form fields:
name, email username, password are all NULL
I don’t understand why as it’s supposed to take all values'/register', function(req, res, next) {
var newUser = new User({
          username: req.body.username,
          password: req.body.password,
          profileImage: profileImageName
Answered question

You need a body parsing middleware to parse incoming request bodies.

Express has a built-in middleware function(which is based on the module “body-parser" ) to parse urlencoded bodies since v4.16.0 onwards. But this built-in parser does not handle multipart bodies.

Since you’re trying to handle multipart/form-data, you may need a middleware like multer.

Answered question
You are viewing 1 out of 1 answers, click here to view all answers.