Reputation: 73
I have nodejs version 10.19.0, ubuntu 20.04.2, and use webstorm ide for javascript. I tried installing both bcrypt and sha256 and neither libraries worked.
For example, after installing bcrypt the first 2 lines in my javascript code is:
const bcrypt = require('bcrypt');
alert('hello');
The alert function only pops up when I comment out the first line. I have the same problem with sha256.
I have tried installing, uninstalling, and reinstalling bcrypt and bcryptjs (even the bcrypt version that was supposed to match my node version). Why can't I seem to get these libraries to install properly? Thanks.
PS. I tried 'npm install bcrypt'
$ npm list -g
(node:40710) ExperimentalWarning: The fs.promises API is
experimental
/home/philip/.nvm/versions/node/v10.16.3/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Upvotes: 2
Views: 19652
Reputation: 73
https://browserify.org/ is the only solution I tried that worked. Thank you everyone for your help.
Edit: I no longer need to use browserify to use bcrypt in my javascript application!
Here are the changes I did to make it work:
In todoApp.html...
<head>
<link rel="stylesheet" type="text/css" href="css/todo.css">
<meta charset="UTF-8">
<title>Todo App</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bcrypt.js"></script>
</head>
...
<script src="scripts/todo.js"></script>
</body>
In todo.js
let bcrypt = dcodeIO.bcrypt;
const saltRounds = 12;
...
Upvotes: 0
Reputation: 169
First of all you should properly look into how to install bcrypt in your project, You can look into this link https://www.npmjs.com/package/bcrypt for detailed installation and you would also be able to get further help from it. But right now the problem is that you are not importing bcrypt properly in your js file. You should import it like this and it will work fine.
const bcrypt = require('bcryptjs')
Upvotes: 1