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

Trevor Maltbie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Trevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 Points

Unable to log the hash

I installed bcrypt on my Mac, at least I think I did because I can see it in the node_modules folder on my system. So, /shrug/.

Anyway, here is my result from trying to follow along with Chalkers in this video:

My code:

const unsecurePlainTextPassword = 'password';
const bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
const someOtherPlaintextPassword = 'not_bacon';
bcrypt.genSalt(saltRounds, function(err, salt) {
    bcrypt.hash(unsecurePlainTextPassword, salt, function(err, hash) {
       console.log(hash)
    });
});

My error in the VSC terminal:

Trevors-iMac:~ trevormaltbie$ node sandbox.js
internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module '/Users/trevormaltbie/sandbox.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Trevors-iMac:~ trevormaltbie$ 

Also, this video is a bit outdated. The README in bcrypt is updated quite a lot since this was made. Not sure I copied the write code? It may be time to re-do this video with updated bcrypt.

This was my install output:

Trevors-iMac:~ trevormaltbie$ python --version
Python 2.7.16
Trevors-iMac:~ trevormaltbie$ python2 --version
-bash: python2: command not found
Trevors-iMac:~ trevormaltbie$ npm install bcrypt --python=python2

> bcrypt@5.0.0 install /Users/trevormaltbie/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[bcrypt] Success: "/Users/trevormaltbie/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
npm WARN saveError ENOENT: no such file or directory, open '/Users/trevormaltbie/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/trevormaltbie/package.json'
npm WARN trevormaltbie No description
npm WARN trevormaltbie No repository field.
npm WARN trevormaltbie No README data
npm WARN trevormaltbie No license field.

+ bcrypt@5.0.0
updated 1 package and audited 135 packages in 1.978s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

1 Answer

Jordan Kittle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,148 Points

FIXED: Deleting the workspace - opening it again and installing bcryptjs instead of bcrypt has worked.

--I had these same issues before trying bcryptjs