Search code examples
node.jsjwtcryptojssecret-key

Generate token using crypto library


I am trying to generate a secret key by running the following command in the terminal: node require('crypto').randomBytes(64).toString('hex')

I am doing this on another tab while the server is running, but getting this as output: zsh: unknown file attribute: h

What am I doing wrong here? TIA


Solution

  • run node command and press enter to go into REPL mode. The you can enter require('crypto').randomBytes(64).toString('hex'). The error is thrown because the characters after node are interpreted as options passed to command.