How to know if script is being run within Nashorn

Alex Soto asotobu at
Tue Sep 16 14:36:23 UTC 2014

I hava a Javascript file and I want to detect who is running it. Let me

The problem is that I want that if this script is run in browser use the IO
streaming API to load content from url, if it is running within node.js it
uses the node.js libraries to read content, and if it is in Nashorn, use
the Java Input stream classes. I have a way to know if the script is run
within a browser or inside Node.js. But I have not found any way to know if
script is running inside Nashorn.

Is there a function that I can call that will return for example some
information about Nashorn that obviously if the script is run outside will
return undefined?

I have thought about using a directly a Java class and if it returns
correctly then I know that is Nashorn, but I would like to know if there is
something more specific of Nashorn.

Thank you so much for your time and help.


  Alex Soto Bueno

More information about the nashorn-dev mailing list