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

// Generate a keypair for this example
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
  modulusLength: 2048,
  publicKeyEncoding: {
    type: 'spki',
    format: 'pem'
  },
  privateKeyEncoding: {
    type: 'pkcs8',
    format: 'pem'
  }
});

// Create a Sign object
const sign = crypto.createSign('SHA256');

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

// Create the signature
const signature = sign.sign(privateKey, 'hex');

console.log('Combined message: First part of the message. Second part of the message. Third part of the message.');
console.log('Signature:', signature);

// You can achieve the same result with a single update
const singleSign = crypto.createSign('SHA256');
singleSign.update('First part of the message. Second part of the message. Third part of the message.');
const singleSignature = singleSign.sign(privateKey, 'hex');

console.log('Single update signature matches multiple updates?', singleSignature === signature);

              
Combined message: First part of the message. Second part of the message. Third part of the message.
Signature: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3
Single update signature matches multiple updates? true