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 (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

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:

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

bcrypt.genSalt(10, function(err, salt){
  bcrypt(unsecurePlainTextPassword, salt, function(err, 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?

Myers Carpenter
Myers Carpenter
6,111 Points

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.