Node.js Processing Pipelines

These processing pipeline execution functions can be used from within a Node.js application or library on a workstation or server.

Similar to the web browser API, most of these functions return a Promise.


runPipelineNode(pipelinePath: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[] | null): Promise<RunPipelineResult>

Run an itk-wasm Emscripten module with Node.js.

pipelinePath: Path to the pre-built pipeline module, without .js or .wasm extensions.

args: A JavaScript Array of strings to pass to the execution of the main function, i.e. arguments that would be passed on the command line to a native executable.

outputs: A JavaScript Array containing JavaScript objects with two properties: path and type.

path is the file path on the virtual filesystem to read after execution has completed.

type is one of the IOTypes:

IOTypes.Text
A string. To write this data type in C++, write a plain text file with, e.g. std::ofstream.
IOTypes.Binary
A binary Uint8Array. To write this data type in C++, read the binary file with, e.g. std::ofstream with the `std::ofstream::binary` flag to std::ofstream::open.
IOTypes.Image
An Image. To write this data type in C++, use the itk::ImageFileWriter, add `WebAssemblyInterface` module to the ITK `find_package` `COMPONENTS` in your *CMakeLists.txt*, and use `.iwi` for the image file name extension.
IOTypes.Mesh
An Mesh. To write this data type in C++, use the itk::MeshFileWriter, add `WebAssemblyInterface` module to the ITK `find_package` `COMPONENTS` in your *CMakeLists.txt*, and use `.json` for the image file name extension.

inputs: A JavaScript Array containing JavaScript objects with three properties: path, type, and data.

data contains the corresponding data to write to the virtual filesystem before executing the module.

path is the file path on the virtual filesystem to read after execution has completed.

type is one of the IOTypes:

IOTypes.Text
A string. To read this data type in C++, read the plain text file with, e.g. std::ifstream.
IOTypes.Binary
A binary Uint8Array. To read this data type in C++, read the binary file with, e.g. std::ifstream with the `std::ifstream::binary` flag to std::ifstream::open.
IOTypes.Image
An Image. To read this data type in C++, use the itk::ImageFileReader, add `WebAssemblyInterface` module to the ITK `find_package` `COMPONENTS` in your *CMakeLists.txt*, and use `.iwi` for the image file name extension.
IOTypes.Mesh
An Mesh. To read this data type in C++, use the itk::MeshFileReader, add `WebAssemblyInterface` module to the ITK `find_package` `COMPONENTS` in your *CMakeLists.txt*, and use `.json` for the image file name extension.

result: A JavaScript object with three properties: stdout, stderr, and outputs.
stdout and stderr are strings. outputs is an array with { path, type, data } content that corresponds to the values specified in the function call.