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

Carlos Lantigua
Carlos Lantigua
5,938 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,366 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,366 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.