Is it possible to run NodeJS JavaScript from Java programs using PolyGlot API.
I need to use require() and await async etcetera.
The use case is to manage Puppeteer script from Graal VM.
It's not officially supported, but have a look at NodeJVM.
Hi,
Since GraalVM 20.0.0, we have experimental support for common.js require(). This way, you can interop from Java to JavaScript (via the Context API) and use npm modules there. You cannot use the Node.js event loop, though, and for some internal packages you have to use replacements (similar to what tools like Browserify would do). See the documentation linked above for more details.
Another option is to start in a node application and then interop into Java. You have to take care around multithreading, but in general, this is possible. See our Blogpost on Multigthreaded Java-JavaScript interoperability.
Best,
Christian
Most helpful comment
It's not officially supported, but have a look at NodeJVM.