# Using Doppler with spawn and mocha

**URL:** <https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533>\
**Category:** Need Help\
**Created:** [May 21, 2024, 7:26pm UTC](https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533 "2024-05-21T19:26:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Disco\_Stew](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/disco_stew/32/688_2.png) [@Disco\_Stew](https://community.doppler.com/u/Disco_Stew)\
**Post date:** [May 21, 2024, 7:26pm UTC](https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533/1 "2024-05-21T19:26:45Z")

</div>

I have code that is using `spawn` to launch mocha.cmd. I am having trouble getting the syntax to get doppler cli prepended to the mocha cli command.

If it was a package.json script I would write as so:

```auto
"test:mocha": "doppler run --command \"mocha --no-deprecation --timeout 600000\""

```

but withing spwan this becomes a bit more complex and I can’t see any examples of how this might work:

```auto
const mocha = spawn(
      "doppler"[
        ("run",
        "--",
        '\\"node_modules\\.bin\\_mocha.cmd',
        [
          "--no-deprecation",
          "--timeout",
          "600000",
        ])
      ]
    );

```

This produces error (which I think i just red herring due to bad parsing of my spawn syntax):

```auto
Mocha error: TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string.

```

I am on Windows platform hence the // in spawn…

---

<div class="post-metadata">

**Author:** ![watsonian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/watsonian/32/267_2.png) [@watsonian](https://community.doppler.com/u/watsonian)\
**Post date:** [May 24, 2024, 8:15pm UTC](https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533/2 "2024-05-24T20:15:35Z")

</div>

Hi @Disco_Stew!

I believe what you’d want should be something like this:

```javascript
const mocha = spawn(
  "doppler",
    [
      "run",
      "--",
      "\\node_modules\\.bin\\_mocha.cmd",
      "--no-deprecation",
      "--timeout",
      "600000"
    ]
);

```

Basically, everything after `doppler` is an argument to the `doppler` binary, so it all goes into the args array. Give that a shot and see if it works for you.

Regards,  
-Joel

---

<div class="post-metadata">

**Author:** ![Disco\_Stew](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/disco_stew/32/688_2.png) [@Disco\_Stew](https://community.doppler.com/u/Disco_Stew)\
**Post date:** [May 26, 2024, 3:18pm UTC](https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533/3 "2024-05-26T15:18:55Z")

</div>

@watsonian That definitely helped, Doppler is now engaged without error, but it is having trouble with the path to mocha.cmd I am guessing by this error:  
`Doppler Error: exec: "\\node_modules\\.bin\\_mocha.cmd": file does not exist`

Correcting the pathing by removing the leading \ fixed it:

```auto
    const mocha = spawn("doppler", [
      "run",
      "--",
      "node_modules\\.bin\\_mocha.cmd",
      "--no-deprecation",
      "--timeout",
      "600000",
    ]);

```

---

<div class="post-metadata">

**Author:** ![watsonian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/watsonian/32/267_2.png) [@watsonian](https://community.doppler.com/u/watsonian)\
**Post date:** [May 28, 2024, 6:29pm UTC](https://community.doppler.com/t/using-doppler-with-spawn-and-mocha/1533/4 "2024-05-28T18:29:45Z")

</div>

@Disco_Stew You may need to put the full path to the file. I’m not 100% sure for Windows environments, but on linux you also use `.` to indicate the current directory, so the relative version of that path would be `.\\node_modules\\.bin\\_mocha.cmd` – might be worth a try as well!
