# How can I solve problem when run test my created node, 'mocha' is not recognized as an internal or external command, operable program or batch file

**URL:** https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374
**Category:** Developing Nodes
**Created:** [28 January 2022 00:40 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374 "2022-01-28T00:40:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)
#### Post date: [28 January 2022 00:40 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/1 "2022-01-28T00:40:54Z")

</div>

Hi all,

I have some problem about unit test my created node.

After I follow help for adding test into my created node.

[node-red-node-test-helper - npm (npmjs.com)](https://www.npmjs.com/package/node-red-node-test-helper)

Then, I run command "npm test", the error has occur.

> 'mocha' is not recognized as an internal or external command, operable program or batch file.

How can I solve this problem? 🤔

Please advice me.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 January 2022 07:46 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/2 "2022-01-28T07:46:50Z")

</div>

In your custom node's package.json file have you defined a "test" script and if so, what is it set to?

Have you added mocha as a devDependency of your module?

---

<div class="post-metadata">

### Author: ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)
#### Post date: [28 January 2022 15:02 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/3 "2022-01-28T15:02:38Z")

</div>

Thank you very much for your reply. 😊

I added "test" in my package.json. But I did not add "mocha" as a devDependencies. So I must add "mocha", right? 🤔

Below is my package.json

```auto
{
  "name": "node-red-contrib-node-line-api",
  "version": "1.0.0",
  "description": "Node Red with LINE API such as LINE Notify and other",
  "license": "Apache-2.0",
  "dependencies": {
    "axios": "^0.24.0",
    "form-data": "4.0.0",
    "querystring": "^0.2.0"
  },
  "main": "node.js",
  "node-red": {
    "nodes": {
      "node-line-notify": "nodes/node-line-notify.js"
    }
  },
  "devDependencies": {
    "node-red": "^2.2.0",
    "node-red-node-test-helper": "^0.2.7"
  },
  "scripts": {
    "test": "mocha \"test/**/*_spec.js\""
  }
}

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [28 January 2022 15:11 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/4 "2022-01-28T15:11:54Z")

</div>

If you have added a test script that wants to use mocha, then yes, you need to add mocha to your project.

---

<div class="post-metadata">

### Author: ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)
#### Post date: [28 January 2022 16:38 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/5 "2022-01-28T16:38:57Z")

</div>

Thank you very much. 😊

After add mocha into my project. Now it can run test.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [11 February 2022 16:39 UTC](https://discourse.nodered.org/t/how-can-i-solve-problem-when-run-test-my-created-node-mocha-is-not-recognized-as-an-internal-or-external-command-operable-program-or-batch-file/57374/6 "2022-02-11T16:39:36Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
