I'm trying to create an simple web page to test the crypto module in js, but even when i use browserify my brower returns Uncaught ReferenceError: require is not defined.
My script.js:
const { createHash } = require('crypto');
function hasher() {
const password = document.getElementById("js_n_password").value;
const hash = createHash(password);
document.getElementById("hashed").innerHTML = password;
}
My index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="bundle.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Web Hash</h1>
<form class="input" id="input">
<label for="n_password">Password:</label>
<input type="password" id="js_n_password" name="n_password">
</form>
<button onclick="hasher()">hash it</button>
<p class="hashed" id="hashed"> </p>
</body>
</html>
Why browserify isn't working and how can i make it work?
PS: add module.exports = function (n) { return n * 111 } to script.js doesn't change anything.