Get started with Kotlin/Wasm and WASI
note
Kotlin/Wasm is in Alpha. It may be changed at any time.
This tutorial demonstrates how to run a simple Kotlin/Wasm application using the WebAssembly System Interface (WASI) in various WebAssembly virtual machines.
You can find examples of an application running on Node.js, Deno, and WasmEdge virtual machines. The output is a simple application that uses the standard WASI API.
Currently, Kotlin/Wasm supports WASI 0.1, also known as Preview 1. Support for WASI 0.2 is planned for future releases.
tip
The Kotlin/Wasm toolchain provides Node.js tasks (
wasmWasiNode*
) out of the box. Other task variants in the project, such as those utilizing Deno or WasmEdge, are included as custom tasks.
Download and install the latest version of IntelliJ IDEA.
Clone the Kotlin/Wasm WASI template repository by selecting File | New | Project from Version Control in IntelliJ IDEA.
You can also clone it from the command line:
git clone git@github.com:Kotlin/kotlin-wasm-wasi-template.git
Open the Gradle tool window by selecting View | Tool Windows | Gradle.
In the Gradle tool window, you can find the Gradle tasks under kotlin-wasm-wasi-example once the project loads.
note
You need at least Java 11 as your Gradle JVM for the tasks to load successfully.
From kotlin-wasm-wasi-example | Tasks | kotlin node, select and run one of the following Gradle tasks:
wasmWasiNodeRun to run the application in Node.js.
wasmWasiDenoRun to run the application in Deno.
wasmWasiWasmEdgeRun to run the application in WasmEdge.
tip
When using Deno on a Windows platform, ensure
deno.exe
is installed. For more information, see Deno's installation documentation.
Alternatively, run one of the following commands in the terminal from the kotlin-wasm-wasi-template
root directory:
To run the application in Node.js:
./gradlew wasmWasiNodeRun
To run the application in Deno:
./gradlew wasmWasiDenoRun
To run the application in WasmEdge:
./gradlew wasmWasiWasmEdgeRun
The terminal displays a message when your application is built successfully:

You can also test that the Kotlin/Wasm application works correctly across various virtual machines.
In the Gradle tool window, run one of the following Gradle tasks from kotlin-wasm-wasi-example | Tasks | verification:
wasmWasiNodeTest to test the application in Node.js.
wasmWasiDenoTest to test the application in Deno.
wasmWasiWasmEdgeTest to test the application in WasmEdge.

Alternatively, run one of the following commands in the terminal from the kotlin-wasm-wasi-template
root directory:
To test the application in Node.js:
./gradlew wasmWasiNodeTest
To test the application in Deno:
./gradlew wasmWasiDenoTest
To test the application in WasmEdge:
./gradlew wasmWasiWasmEdgeTest
The terminal displays the test results:

Join the Kotlin/Wasm community in Kotlin Slack:
Try more Kotlin/Wasm examples: