83
rated 0 times
[
86]
[
3]
/ answers: 1 / hits: 112226
/ 14 Years ago, fri, november 19, 2010, 12:00:00
I have a script I am requiring from a Node.js script, which I want to keep JavaScript engine independent.
For example, I want to do exports.x = y;
only if it’s running under Node.js. How can I perform this test?
When posting this question, I didn’t know the Node.js modules feature is based on CommonJS.
For the specific example I gave, a more accurate question would’ve been:
How can a script tell whether it has been required as a CommonJS module?
More From » node.js