Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript npm Basics 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,937 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,304 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,937 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,304 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.