Install Javonet for Node.js

Javonet is available as a Node.js package, which can be installed using NPM package manager or any other method which supports Node.js packages. For applications using Nodejs 12 and higher use javonet-nodejs-sdk Package

Activate Javonet

Use register or log in pages to obtain license key. An e-mail and license key is necessary to activate Javonet.

First sample application

Javonet needs to be imported as any other dependency.

const { Javonet } = require('javonet-nodejs-sdk/lib/Javonet')

Javonet needs to be activated first. Activation must be called only once at the start-up of an application. During the first activation, license server are called and a javonet.lic file is generated.

Javonet.activate("your-license-key")

To use other programming technology, Runtime Context of the called technology needs to be created.

let pythonRuntime = Javonet.inMemory().python()

RuntimeContext refers to single instance of the called runtime. Once it is created it is used to interact with called runtime. The simplest use case is to get from target technology a type from a built-in library:

let pythonType = pythonRuntime.getType('math').execute()

And then get static field from the type:

let response = pythonType.getStaticField("pi").execute()

The returned value needs to be cast to calling technology type and can be used as any other variable:

let result = response.getValue()
console.log(result)

To sum up, the whole code snippet looks like:

// <Activation>
Javonet.activate("your-license-key")
// </Activation>

// <RuntimeContextCreation>
let pythonRuntime = Javonet.inMemory().python()
// </RuntimeContextCreation>

// <GetType>
let pythonType = pythonRuntime.getType('math').execute()
// </GetType>

// <GetStaticField>
let response = pythonType.getStaticField("pi").execute()
// </GetStaticField>

// <GetValue>
let result = response.getValue()
console.log(result)
// </GetValue>