Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for node.js to import a java library

Tags:

java

node.js

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)

like image 643
i8abug Avatar asked Dec 21 '14 18:12

i8abug


People also ask

Can I use Java library in JavaScript?

Java libraries can be accessed from JavaScript in GraalVM through the Java built-in object.

Is node JS compatible with Java?

You can intergrate NodeJS with Java using node-java.

Does node js support import?

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.


1 Answers

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/

like image 87
codelion Avatar answered Oct 06 '22 00:10

codelion