I’m writing some encryption functions in NodeJS. The functions work like createCipheriv(encryptionType, text, key, iv ). The key needs to be 32 characters long, and the IV needs to be 16 characters long. So, I want to do something like:
if (process.env.IV.length() === 16 || process.env.key.length() === 32) {
module.exports = encryptionFunctions
} else {
module.exports = undefined;
console.error("IV or key lengths are incorrect")
}
The error object has been around since the beginning of javascript. All it does is simply storing an error message and collecting the stack trace of where the error appeared from. However throw simply takes any object or value and calls .toString() and outputs it to stderr.
In a node process the console has two different output streams, stdout and stderr, every console method uses stdout except console.error which uses stderr. The point of having two different output streams is to separate error logs and debug/access/etc logs