Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript npm Basics (retiring) Installing Packages with npm Installing Local Packages

I can not figure out what I'm doing wrong?

THIS IS MY CODE
var unsecurePlainTextPassword = "password";

var bcrypt = require('bcrypt');
bcrypt.genSalt(saltRounds, function(err, salt) {
    bcrypt.hash(unsecurePlainTextPassword, salt, function(err, hash) {
        console.log(hash);
    });
});

THIS IS THE MESSAGE

bcrypt.genSalt(saltRounds, function(err, salt) {
               ^

ReferenceError: saltRounds is not defined
    at Object.<anonymous> (/Users/sharifi/Documents/nn/app.js:4:16)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:190:16)
    at bootstrap_node.js:662:3
Carlos Lantigua
Carlos Lantigua
5,938 Points

I just posted the same thing, having the same issue as well, I have to run this from my personal editor because workspace console seems to be offline at the moment for me.

2 Answers

Adam Beer
Adam Beer
11,314 Points

What is the "saltRounds"? Rewrite "saltNumber" to a number. If I remember correctly now you specify how many characters your password will convert to. Hope this help.

Carlos Lantigua
Carlos Lantigua
5,938 Points

per the readme, this is the recommended code for bcrypt to use, it differs heavily from the video Andrew Chalky is presenting as I think it has been updated since, this seems to be causing an issue to run it. We don't exactly know what it means yet because we haven't gotten far enough to know what it is yet lol.

Adam Beer
Adam Beer
11,314 Points

The code worked for me with saltNumber. I don't understand why don't working for you.

var unsecurePlainTextPassword = "password";

var bcrypt = require('bcrypt');
bcrypt.genSalt(saltRounds, function(err, salt) {
    bcrypt.hash(unsecurePlainTextPassword, salt, function(err, hash) {
        console.log(hash);
    });
});

I finally got the answer. for 'saltRounds' in the "bcrypt.getSlat", we should put a number. For example 10.