Generate secret key in node js

Updated at 09-Aug-2022, By samar

Generate secret key in node js

With this article, we will examine several different instances of how to solve the "Generate secret key in node js".

How can i generate a secret key from a string in node js. I have to generate a secret key of a string using crypto in node project.
  • You have to install crypto for your node by running below command

    npm install crypto
    

    After using command you can use below script

    const crypto = require('crypto');
    const secret = 'randomtext';
    const hash = crypto.createHmac('sha256', secret).digest('hex');
    console.log(hash);
    

Back to code snippet queries related nodejs