Before getting started, make sure Node.js and Docker are installed. On Linux, make sure you can run
sudo. On Windows, make sure Shared Drives are enabled in the Docker settings. On Windows, also install Git Bash, and run shell commands in Git Bash.
First, let’s create a new folder to house our project.
Initialize the Node package.json file:
npm init --yes
fs-extra to your project’s dependencies:
npm install --save itk fs-extra
Let’s write some code! Populate hello.cxx with our Hello World program:
Next, provide a CMake build configuration at CMakeLists.txt:
We use the
add_executable command to build executables with itk.js. The Emscripten toolchain along with itk.js build and execution configurations are contained in the itk.js dockcross Docker image used by the itk-js command line interface (CLI).
Note that the same code can also be built and tested with native operating system build tools. This is useful for development and debugging.
Next, build the program with the itk.js CLI,
itk-js. This is shipped with the
itk package, and the CLI can be executed from the local node_modules folder with
itk-js CLI will invoke the toolchain contained in the dockcross Docker image. Pass the local source code directory root into
itk-js build to perform the build.
npx itk-js build .
The project is built in
To execute the project, create an
index.js file to invoke the module:
const path = require('path')
And run it!
npx node ./index.js