I totally agree with the solutions given by @jacqueline-bosco and @ishrth_fathima you can use stream-based Hashing :
const crypto = require('crypto');
const fs = require('fs');
const hash = crypto.createHash('sha256');
const input = fs.createReadStream('path/to/file');
input.pipe(hash).setEncoding('hex').on('finish', () => {
console.log(hash.read());
});