I have a piece of JavaScript that is designed to be run inside NodeJS, otherwise it breaks (for instance, it makes use of require()
). I'd like to make a runtime check that it's inside NodeJS and produce a clear error message otherwise.
I've seen this answer explaining how to check if the code is being run inside browser. However it doesn't check if there's NodeJS.
How do I check my JavaScript is run inside NodeJS?