How to generate a SHA-256 hash with JavaScript

How to generate a SHA-256 hexadecimal hash using Node.js and JavaScript in the browser.