Running app in nodejs
It is easy to use Fluence JS in NodeJS applications. You can take full advantage of the javascript ecosystem and at the save time expose service to the Fluence Network. That makes is an excellent choice for quick prototyping of applications for Fluence Stack.
Configuring application to run in nodejs
@fluencelabs/fluence delivers AquaVM wasm file through the npm package. No additional configuration is needed.
Calc app example
Lets implement a very simple app which simulates a desk calculator. The calculator has internal memory and implements the following set of operations:
Add a number
Subtract a number
Multiply by a number
Divide by a number
Get the current memory state
Reset the memory state to 0.0
First, let's write the service definition in aqua:
-- service definition
service Calc("calc"):
add(n: f32)
subtract(n: f32)
multiply(n: f32)
divide(n: f32)
reset()
getResult() -> f32Now write the implementation for this service in typescript:
As you can see all the service logic has been implemented in typescript. You have full power of npm at your disposal.
Now try running the application:
And the service can be called from aqua. For example:
Last updated
Was this helpful?