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

TypeError: bcrypt is not a function

After reading other discussion posts to this video, I have tried this with bcrypt annd bcryptjs. However, both provide me with this error

/home/treehouse/workspace/app.js:5
bcrypt(unsecurePlainTextPassword, salt, function(err, hash){
^

TypeError: bcrypt is not a function
at /home/treehouse/workspace/app.js:5:3
at Immediate._onImmediate (/home/treehouse/workspace/node_modules/bc ryptjs/dist/bcrypt.js:155:21)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)

my code is in app.js:

app.js
var unsecurePlainTextPassword = "password";
var bcrypt = require('bcryptjs');

bcrypt.genSalt(10, function(err, salt){
  bcrypt(unsecurePlainTextPassword, salt, function(err, hash){
    console.log(hash);
  });
});

3 Answers

You are missing .hash in this line

bcrypt(unsecurePlainTextPassword, salt, function(err, hash){

It should be:

bcrypt.hash(unsecurePlainTextPassword, salt, function(err, hash) {

Thank you so much for catching that.

Is anyone else having a problem with workspace loosing connection since installing npm?

Winnie Kelley : are you maybe installing the package bcrypt rather than bcryptjs? The first package installs many many extra packages that is unfortunately making the workspace server timeout.