Get your own Node server
const crypto = require('crypto');

// Secret key
const secretKey = 'my-secret-key';

// Create an Hmac object
const hmac = crypto.createHmac('sha256', secretKey);

// Update the hmac with multiple pieces of data
hmac.update('First part of the data.');
hmac.update(' Second part of the data.');
hmac.update(' Third part of the data.');

// Calculate the final digest
const digest = hmac.digest('hex');

console.log('Combined data: First part of the data. Second part of the data. Third part of the data.');
console.log('Secret Key:', secretKey);
console.log('HMAC-SHA256:', digest);

// You can achieve the same result with a single update
const singleHmac = crypto.createHmac('sha256', secretKey);
singleHmac.update('First part of the data. Second part of the data. Third part of the data.');
const singleDigest = singleHmac.digest('hex');

console.log('Single update HMAC matches multiple updates?', singleDigest === digest);

              
Combined data: First part of the data. Second part of the data. Third part of the data.
Secret Key: my-secret-key
HMAC-SHA256: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3
Single update HMAC matches multiple updates? true