create hash in node js

const crypto = require('crypto');

const inputString = 'Hello, this is a message to hash'; const hash = crypto.createHash('sha256').update(inputString).digest('hex');

Explanation: 1. First, import the built-in 'crypto' module in Node.js, which provides cryptographic functionality.

  1. Define the input string that you want to hash.

  2. Use the crypto.createHash() method to create a hash object using the specific algorithm (in this case, 'sha256').

  3. Call the update() method on the hash object, passing the inputString as the data to be hashed.

  4. Finally, call the digest() method on the hash object with 'hex' as the encoding to obtain the hashed value as a hexadecimal string.