# MedianFilterTest, ITK-WASM, ITK-JS, ITK-JS-VTK, crashed when running npx node index.mjs ./cthead.png ./cthead1.out.png 4

**URL:** <https://discourse.itk.org/t/medianfiltertest-itk-wasm-itk-js-itk-js-vtk-crashed-when-running-npx-node-index-mjs-cthead-png-cthead1-out-png-4/5223>\
**Category:** Engineering\
**Tags:** itk-wasm\
**Created:** [July 28, 2022, 10:55am UTC](https://discourse.itk.org/t/medianfiltertest-itk-wasm-itk-js-itk-js-vtk-crashed-when-running-npx-node-index-mjs-cthead-png-cthead1-out-png-4/5223 "2022-07-28T10:55:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [July 28, 2022, 10:55am UTC](https://discourse.itk.org/t/medianfiltertest-itk-wasm-itk-js-itk-js-vtk-crashed-when-running-npx-node-index-mjs-cthead-png-cthead1-out-png-4/5223/1 "2022-07-28T10:55:42Z")

</div>

Hi @dzenanz,

I am stuck in ITK-JS, ITK-WASM.  
Environment:  
VSCODE: latest version  
Node version: node.js 16.15.1  
npm version: 8.11.0  
EDI: Visual studio code/WSL2(widows linux subsystem) works fine.  
docker desktop: installed working fine, all thimages of insighttoolkit is there such as ITK-JS, VTK-JS, ITK-JS-VTK, Emscripten, etc. all images are working fine.  
Samples: HelloWorld built and worlks.  
I am working with itk.js or itk-wasm. I have following sample project from itk-wasm/test/ directory in the ITK-WASM repository called MedianFilterTest. The [itk-js build ./] builds the project and puts everything inside the web-build, but when i try to run it in node.js using following command [npx node index.mjs ./cthead1.png.json ./cthead1\_out.png.json 4] it fails, i also tried [npx node index.mjs] and again it throws exception with a lot of javascript on the screen.  
i provided you with some files of my project and screen shots that may come helpful.

[CMakeLists.txt](https://discourse.itk.org/uploads/short-url/3lMeyBDJOSVF6z2zZkAB4B18ZZe.txt) (584 Bytes)

[cthead1.png.json](https://discourse.itk.org/uploads/short-url/6lRV0IJblT2fnOxu9kzJpNmRfjf.json) (10.3 KB)

[MedianFilterTest.cxx](https://discourse.itk.org/uploads/short-url/rzRBfhm2HKSdIfIxLxIy9omioBu.cxx) (2.0 KB)

[package.json](https://discourse.itk.org/uploads/short-url/fRliLzweYiiOxuNdQ66ZVbGKno1.json) (392 Bytes)

[package-lock.json](https://discourse.itk.org/uploads/short-url/cjGzfvlHyKeGskwWK0oQ0gw50c3.json) (12.1 KB)

 ![cthead1](https://discourse.itk.org/uploads/default/original/2X/9/9cad6f6dfb1fb6534b7b97a150488503c2e04826.png)

runing the project using npx package runner in node.js results in a crash in runPipelineNode line no idea why

 ![npx-node-index.mjs-cthead1.png.json-cthead1_out.png.json-radius1part](https://discourse.itk.org/uploads/default/original/2X/a/a424107f64688f4c88d898983084f4b1b2cd4896.png)

this screen shot displays the resulting exception error. a lot of javascript code dumps on the screen no idea why?

 ![npx-node-index.mjs-cthead1.png.json-cthead1_out.png.json-radius-2part](https://discourse.itk.org/uploads/default/original/2X/4/4531ba4720f3149c2e69adbb58627a6dee6bcd1c.png)

Web-build folder on the left sidebar boxed up in with a red pen.

 ![web-build-directory](https://discourse.itk.org/uploads/default/original/2X/0/0ed5e4269fc6289fe5756696ecef9044a789c383.png)

I found your name from communication with matt maccormic one of major people involved in itk vtk and i saw the communication and your question which was very useful, but still my sample project crashing.

# index.mjs javascript code:

```js
const testOutputFilePath = path.resolve(‘cthead1_out.png.json’);

const testInputFilePath = path.resolve(‘cthead1.png.json’);

console.log(“testInputFilePath”, testInputFilePath)

console.log(“testOutputFilePath”, testOutputFilePath)

import path from “path”
import { IOTypes, readImageLocalFile, writeImageLocalFile, runPipelineNode, imageSharedBufferOrCopy } from “itk-wasm”
import { argv, argv0, stderr } from “process”

console.log(“index.mjs: inside the module”);
console.log(“argv[0]”, process.argv[0]);
console.log(“argv[1]”, process.argv[1]);
console.log(“argv[2]”, process.argv[2]);
console.log(“argv[3]”, process.argv[3]);
console.log(“argv[4]”, process.argv[4]);
console.log(“===========================================”);

const ARGV1 = process.argv[1];
const ARGV2 = process.argv[2];
const ARGV3 = process.argv[3];
const ARGV4 = process.argv[4];

console.log(‘ __dirname’,__ dirname)

readImageLocalFile(testInputFilePath)
.then(function (image) {
const args = [‘cthead1.png.json’, ‘cthead1_out.png.json’, ‘4’]
const pipelinepath = path.resolve(“web-build”, ‘MedianFilterTest2’)
const desiredOutput = [{ path: args[1], IOTypes: IOTypes.Image }]

    const inputs = [{ path: args[0], type: IOTypes.Image, data: image }]
    console.log('Before runPipelineNode');
    return runPipelineNode(pipelinepath, args, desiredOutput, inputs)
}).then(function ({ stdout, stderr, outputs }) {
    console.log('After runPipelineNode')
    const useCompression = false;
    return writeImageLocalFile(useCompression, outputs[0].data, testOutputFilePath)
}).then(function () {
    console.log('DEBUG script runned - output image is written to the local disk.')
})

```

i think the problem is the index.mjs file and the javascript code not correct.  
i use runPipelineNode(pipelinepath, args,output, inputs) call to call the c++ backend code from javascript.  
Matt mentioned in a post to use runPipelineBrowser which i dont know exactly how to call it from javascript code in index.mjs. FYI index.mjs is module form of index.js , dou you have your index.js or index.mjs to send me your javascript code calling a c++ filter pipeline or MedianFilterTest.cxx pipeline. just tell me what am i doing wrong ?

BYW, why should we pass images to runPipelineNode in as cthead.png.json in json format? I appreciate if someone explains that because i could not find anything about that.

i appreciate your help

Best  
sohrab azami  
@sag

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 28, 2022, 12:16pm UTC](https://discourse.itk.org/t/medianfiltertest-itk-wasm-itk-js-itk-js-vtk-crashed-when-running-npx-node-index-mjs-cthead-png-cthead1-out-png-4/5223/2 "2022-07-28T12:16:36Z")

</div>

If you use [code formatting](https://discourse.stonehearth.net/t/discourse-guide-code-formatting/30587), the post is easier to read.

@matt.mccormick can best answer this question.

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [July 28, 2022, 12:29pm UTC](https://discourse.itk.org/t/medianfiltertest-itk-wasm-itk-js-itk-js-vtk-crashed-when-running-npx-node-index-mjs-cthead-png-cthead1-out-png-4/5223/3 "2022-07-28T12:29:30Z")

</div>

Thank you @dzenanz

BR  
@sag
