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

npm Basics > Installing Packages with npm > Installing Local Packages

Andrew Chalkley:

I'm having a problem installing "bcrypt" in the console. I did "npm install bcrypt" & tried to uninstall "bcrypt" to start over from the begining & then reinstall it, but I'm getting error messages. How do I clean out "bcrypt" completely & start from scratch?

Here's the code I'm seeing: treehouse:~/workspace$ npm install bcrypt

bcrypt@0.8.7 install /home/treehouse/workspace/node_modules/bcrypt
node-gyp rebuild

make: Entering directory /home/treehouse/workspace/node_modules/bcrypt/build' CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node COPY Release/bcrypt_lib.node make: Leaving directory/home/treehouse/workspace/node_modules/bcrypt/build'
/home/treehouse/workspace
└─┬ bcrypt@0.8.7
├── bindings@1.2.1
└── nan@2.3.5

npm WARN enoent ENOENT: no such file or directory, open '/home/treehouse/workspace/package.json' npm WARN workspace No description
npm WARN workspace No repository field.
npm WARN workspace No README data
npm WARN workspace No license field.

2 Answers

Miguel Canas
seal-mask
.a{fill-rule:evenodd;}techdegree
Miguel Canas
Python Development Techdegree Student 11,470 Points

Hi Andrew,

Based on the output you included in the message it appears that bcrypt installed successfully. The npm WARN statements can be ignored, they do not indicate that the package failed to install..

You can verify that the package did install by typing the following commands in the workspace console:

~/workspace$ node
> console.log(require('bcrypt'));

You should get the following output:

{ genSaltSync: [Function],
  genSalt: [Function],
  hashSync: [Function],
  hash: [Function],
  compareSync: [Function],
  compare: [Function],
  getRounds: [Function] }

Hope that helps!

~ Miguel

Miguel Canas & Andrew Chalkley:

Thanks. I was the person who wrote the question. I directed the question to Andrew Chalkers, the instructor.

Ubuntu Linux is new to me & I've never used it until recently. It's awkward to type commands on a line without knowing what I'm doing. I'll review this lesson to be sure it's O.K. When I initially installed "bcrypt" the very first time, my screen didn't look at all the same as the instructor's screen in the video. It throws me off because the "bcrypt" code has been updated a lot since over 1 year ago. The Python used in Workspace was updated since then, too, so it would have helped to have comments under the teacher's notes.

I just tried "node app.js" in the console. This is what appeared:

var unsecurePlainTextPassword = "password";

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

treehouse:~/workspace$ node app.js
/home/treehouse/workspace/app.js:4
bcrypt.genSalt(saltRounds, function(err, salt) {
^

ReferenceError: saltRounds is not defined
at Object.<anonymous> (/home/treehouse/workspace/app.js:4:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
treehouse:~/workspace$

Miguel Canas:

I tried your code above, & I got the same results except the word "undefined" at the bottom of the above list.

Miguel Canas
seal-mask
.a{fill-rule:evenodd;}techdegree
Miguel Canas
Python Development Techdegree Student 11,470 Points

Hi Kathryn,

I get the same thing, I just didn't include it in that code snippet. You can ignore that undefined. When you call console.log() it will return undefined after logging anything you pass to it.

In your previous comment you're getting that ReferenceError because saltRounds is never defined in your app.js file.

Try defining a saltRounds variable before you you call the bcrypt.genSalt() method, or pass a number instead.

Miguel Canas:

Here's what I did. I changed the "saltRounds" in line 4 of app.js to "10" (without quotes), & I got the string when I entered "node app.js". The JavaScript code in the bcrypt README.md file had "saltRounds" in it. See below:

Change the updated bcrypt JavaScript code from: bcrypt.genSalt(saltRounds, function(err, salt)) to bcrypt.genSalt(10, function(err, salt)), & you get the hash string.

Thanks, Miguel.