title: Bcrypt illegal argument: number
body: <p>I'm having issues with bcrypt and I'm not sure why. Here is my code for a basic registration route:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const bcrypt = require('bcryptjs');
  const passport = require('passport');
  
  // Register
  router.post('/register', function(req, res){
  
    req.checkBody('username', 'Username is Required').notEmpty();
    req.checkBody('kingname', 'Kingdom Name is Required').notEmpty();
    req.checkBody('email', 'E-Mail is Required').notEmpty();
    req.checkBody('password', 'Password is Required').notEmpty();
    req.checkBody('password2', 'Passwords do not match').equals(req.body.password);
  
    var errors = req.validationErrors();
  
    if(errors) {
      res.render('index', {
        errors: errors
      });
    } else {
      var newUser = {
        username: req.body.username,
        kingname: req.body.kingname,
        email: req.body.email,
        password: req.body.password,
        password2: req.body.password2
      }
  
    bcrypt.getSalt(10, function(err, salt){
      bcrypt.hash(newUser.password, salt, function(err, hash){
        if(err) {
          console.log(err);
        }
        newUser.password = hash;
        let post = {username: newUser.username, password: newUser.password, email: newUser.email, kingname: newUser.kingname};
        let sql ='INSERT INTO users SET ?';
        let query = db.query(sql, post, function(err, res){
          if(err) {
            console.log(err);
            return;
          } else {
          user_id = res.insertID;
          console.log('Last User ID', res.insertID);
          console.log('User registration successful...');
          res.redirect('/');
          }
        });
      });
    });
    }
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Now the error I'm getting is this:</p>
  
  <blockquote>
  <pre><code>Error: Illegal arguments: number
      at Object.bcrypt.getSalt (/home/kogadmin/www/node_modules/bcryptjs/dist/bcrypt.js:339:19)
      at /home/kogadmin/www/routes/reg.js:30:10
      at Layer.handle [as handle_request] (/home/kogadmin/www/node_modules/express/lib/router/layer.js:95:5)
      at next (/home/kogadmin/www/node_modules/express/lib/router/route.js:137:13)
      at Route.dispatch (/home/kogadmin/www/node_modules/express/lib/router/route.js:112:3)
      at Layer.handle [as handle_request] (/home/kogadmin/www/node_modules/express/lib/router/layer.js:95:5)
      at /home/kogadmin/www/node_modules/express/lib/router/index.js:281:22
      at Function.process_params (/home/kogadmin/www/node_modules/express/lib/router/index.js:335:12)
      at next (/home/kogadmin/www/node_modules/express/lib/router/index.js:275:10)
      at Function.handle (/home/kogadmin/www/node_modules/express/lib/router/index.js:174:3)
  </code></pre>
  </blockquote>
  
  <p>Which is why I'm a bit confused. The way the error looks is that it is saying the 10 is the illegal argument, which it isn't, I've made sure that the syntax was correct from their documentation.</p>