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

// Using the RFC 3526 MODP Group 14 (2048 bits)
console.log('Alice: Creating DiffieHellman using predefined group...');
const alice = crypto.getDiffieHellman('modp14');
alice.generateKeys();

// Bob also uses the same predefined group
console.log('Bob: Creating DiffieHellman using predefined group...');
const bob = crypto.getDiffieHellman('modp14');
bob.generateKeys();

// Exchange public keys (over an insecure channel)
console.log('Exchanging public keys...');
const alicePublicKey = alice.getPublicKey();
const bobPublicKey = bob.getPublicKey();

// Compute shared secrets
const aliceSecret = alice.computeSecret(bobPublicKey);
const bobSecret = bob.computeSecret(alicePublicKey);

// Verify that the shared secrets match
console.log('Do the shared secrets match?', aliceSecret.equals(bobSecret));

// Output information about the group
console.log('Group prime size:', alice.getPrime().length * 8, 'bits');
console.log('Generator value:', alice.getGenerator().toString('hex'));

// List all available predefined groups
console.log('\nAvailable predefined groups:', crypto.getDiffieHellmanGroups());

              
Alice: Creating DiffieHellman using predefined group...
Bob: Creating DiffieHellman using predefined group...
Exchanging public keys...
Do the shared secrets match? true
Group prime size: 2048 bits
Generator value: 02

Available predefined groups: [
  'modp1',  'modp2',  'modp5',
  'modp14', 'modp15', 'modp16',
  'modp17', 'modp18'
]