Skip to main content

Using the Node Host SDK

Check your installation

Please be sure you've installed Extism before continuing with this guide.

1. Install the Node module

Install via npm:

npm install @extism/extism --save

2. Import the module and use the APIs

Count Vowels Plugin

code.wasm in this example is our example plugin that counts vowels. If you want to run this, download it first and set the path:

curl > code.wasm
const { withContext, Context } = require('@extism/extism');
const { readFileSync } = require('fs');

withContext(async function (context) {
let wasm = readFileSync('../wasm/code.wasm');
// NOTE: if you encounter an error such as:
// "Unable to load plugin: unknown import: wasi_snapshot_preview1::fd_write has not been defined"
// change the second parameter to `true` in the following function to provide WASI imports to your plugin.
let p = context.plugin(wasm, false, functions);

if (!p.functionExists('count_vowels')) {
console.log("no function 'count_vowels' in wasm");

let buf = await'count_vowels', process.argv[2] || 'this is a test');

// or, use a context like this:
let ctx = new Context();
let wasm = readFileSync('../wasm/code.wasm');
let p = ctx.plugin(wasm);
// ... where the context can be passed around to various functions etc.

Host Functions

It is also possible to create functions to expose additional functionality from the host by using Host Functions.

Count Vowels Plugin

To run this example, use the version of the count vowels plugin with the example host function:

curl > code.wasm
function hello_world(currentPlugin, inputs, outputs, userData, userData1) {
console.log("Hello from Javascript!");
// Print data pointed to by input pointer
let mem = currentPlugin.memory(inputs[0].v.i64);
// Print user data
outputs[0] = inputs[0];

Then add it to the plugin when it's created:

let functions = [
new HostFunction(
"Hello again!",
"Hello once more!",

let p = context.plugin(wasm, true, functions);

Need help?

If you've encountered a bug or think something is missing, please open an issue on the Extism GitHub repository.

There is an active community on Discord where the project maintainers and users can help you. Come hang out!