javascript - How do I create a new instance of a Schema and save it to the database? -


i have userschema has 2 strings: username , password.

i trying add new user database through html form.

i have route: '/signup'

this have:

app.post('/signup', function(req, res){    // hash password    var salt = bcrypt.gensaltsync(10);    var hash = bcrypt.hashsync(req.body.password, salt);      user.create({username: req.body.username, password: hash}, function (err, user) {      console.log("signing up...");       if (err){         console.log("something went wrong");         return res.redirect('/signup');       }       saved!    });  });

i have been following mix of different tutorials , videos. debugging know salt/hashing fine. it's create causing problem. when submit html form, hangs

i realised not redirecting anywhere when successful. added in redirect , works now.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -