title: How to generate a nonce in node.js?
body: <p>I need to generate a nonce (number generated only once) to remove the CSP rule <code>'unsafe-inline'</code> and all the trusted URLs for scripts, improving the CSP score. Thus I need to have in the HTML</p>
  
  <pre><code>&lt;script nonce="{{{nonce}}}" src="http://example.com/file.js"&gt;
  </code></pre>
  
  <p>I know the nonce must be unique with a method of calculation almost impossible to predict, it should have at least 128 bits (hence 16 bytes), and be encoded in base64. Is therefore this correct for <code>node.js</code>?</p>
  
  <pre><code>const crypto = require('crypto');
  let nonce = crypto.randomBytes(16).toString('base64');
  </code></pre>