Just add a tip: Key length is dependent on the algorithm, such as for aes192, it’s 24 bytes, or aes256, it’s 32 bytes.
You need to have a key length of 32 byte (256 bit).
So if you change your key line to:
let key = crypto.createHash('sha256').update(String(secret)).digest('base64').substr(0, 32);
it will work.