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

Carlos Lantigua
Carlos Lantigua
5,937 Points

Installing Local Packages nmp basics

per the readme recommended code I used

var unsecurePlainTextPassword = "password";
var bcrypt = require('bcrypt'); //added this after Andrews video, does the same without it
bcrypt.genSalt(saltRounds, function(err, salt) {
    bcrypt.hash(unsecurePlainTextPassword, salt, function(err, hash) {
        console.log(hash);
    });
});

I get the following error in the command line

```Command line Treehouse_JavaScript_Basics\npm\app.js:3 bcrypt.genSalt(saltRounds, function(err, salt) { ^

ReferenceError: saltRounds is not defined at Object.<anonymous> (F:\programingProjects\Treehouse_JavaScript_Basics\npm\app.js:3:16) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3) at Function.Module.runMain (internal/modules/cjs/loader.js:695:10) at startup (internal/bootstrap/node.js:201:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

I notice the command line this is hard to read but the up arrow in the command line is pointing at the word "saltRounds" in the second line of the command line.

2 Answers

Heidi Puk Hermann
Heidi Puk Hermann
33,351 Points

instead of nalrrounds you need to give it an integer. I the lecture he uses 10; If you do the same, it should work!

Michael Williams
Michael Williams
Courses Plus Student 8,059 Points

Heidi Puk Hermann Why does putting 10 in there work? I know it's defining the parameter, but what's the significance of it?

Heidi Puk Hermann
Heidi Puk Hermann
33,351 Points

I comes from the way the gensalt()-function is defined. It takes an integer defining how many times the password is getting hashed. If saltRounds had been defined as some integer value earlier in the code, there would not have been any error.

You can read more about it in the documentation.