Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. const express = require("express");
  2. const bcrypt = require("bcrypt");
  3.  
  4. const User = require("../models/user");
  5.  
  6. const router = express.Router();
  7.  
  8.  
  9. router.post("/signup", (req, res, next) =>{
  10. bcrypt.hash(req.body.password, 10)
  11. .then(hash =>{
  12. const user = new User({
  13. email: req.body.email,
  14. password: hash
  15. });
  16. user.save()
  17. .then(result =>{
  18. res.status(201).json({
  19. message: 'User created!',
  20. result: result
  21. })
  22. })
  23. .catch(err => {
  24. res.status(500).json({
  25. error: err
  26. });
  27. });
  28. });
  29. });
  30.  
  31.  
  32.  
  33.  
  34.  
  35. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement