Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate secret key in NodeJS
require('crypto').randomBytes(48, function(err, buffer) { var token = buffer.toString('hex'); console.log(token); });
@olliechick

This comment has been minimized.

Copy link

@olliechick olliechick commented Sep 9, 2020

This can also be run synchronously: var token = require('crypto').randomBytes(48).toString('hex'); console.log(token);

@alexrogersdesign

This comment has been minimized.

Copy link

@alexrogersdesign alexrogersdesign commented Sep 25, 2020

You don't even need the var: console.log(require('crypto').randomBytes(48).toString('hex'))
you could go even further and run it as a bash command node -e console.log(require('crypto').randomBytes(48).toString('hex'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment