I have a nodejs application that has some expensive computations. I'm thinking of doing this part in java so I can more easily take advantage of threading and math libraries. Is there an easy way to have nodejs talk to external java libraries?
The java library will contain a loop that frequently calls javascript functions. Will I see a big performance hit due to having these two libraries constantly cross talk (rather than packaging the entire task, sending it to the jvm, and then getting a result back)
Java libraries can be accessed from JavaScript in GraalVM through the Java built-in object.
You can intergrate NodeJS with Java using node-java.
NodeJS allows us to import CommonJS modules from ES Modules. If we would like to import our CommonJS class export example from above, our ES Module import would look like this: // index.
It may be better to just create a java server to do the computations and communicate with your node.js application over a messaging queue. Here is an example which shows how to do that - http://blog.james-carr.org/2010/09/09/rabbitmq-nodejs-and-java-goodness/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With