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

Steve Mustanski
Steve Mustanski
15,081 Points

Problem installing bcrypt in workspaces

I get the following error when installing bcrypt:

[bcrypt] Success: "/home/treehouse/workspace/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote                           
/home/treehouse/workspace                                                                                                                       
└── bcrypt@2.0.1                                                                                                                                

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.  

when I run app.js I get the following error:

bcrypt.genSalt(saltRounds, function(err, salt) {                                                                                                        
^                                                                                                                                               

ReferenceError: bcrypt is not defined                                                                                                           
    at Object.<anonymous> (/home/treehouse/workspace/app.js:3:1)                                                                                
    at Module._compile (module.js:570:32)                                                                                                       
    at Object.Module._extensions..js (module.js:579:10)                                                                                         
    at Module.load (module.js:487:32)                                                                                                           
    at tryModuleLoad (module.js:446:12)                                                                                                         
    at Function.Module._load (module.js:438:3)                                                                                                  
    at Module.runMain (module.js:604:10)                                                                                                        
    at run (bootstrap_node.js:389:7)                                                                                                            
    at startup (bootstrap_node.js:149:9)                                                                                                        
    at bootstrap_node.js:504:3     

Anyone else run into this and solve it?

1 Answer

Adam Beer
Adam Beer
11,304 Points

I also ran into this bcrypt problem. I solved it, like this:

npm install bcryptjs

var bcrypt = require('bcryptjs');

Hope this help!

Steve Mustanski
Steve Mustanski
15,081 Points

I completely forgot about requiring it. I had to require(bcrypt) though is that is what I installed. It is working now. Thanks!