# Johnny-five Version 2.1 under Windows

**URL:** <https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654>\
**Category:** General\
**Created:** [12 August 2021 11:02 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654 "2021-08-12T11:02:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JK40105](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jk40105/32/38882_2.png) [@JK40105](https://discourse.nodered.org/u/JK40105)\
**Post date:** [12 August 2021 11:02 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654/1 "2021-08-12T11:02:53Z")

</div>

As described in my post "Problem with johnny-five version 2.0" fro May 15, the "new" keyword is required in order to create an instance of the Board class. This keyword cannot be inserted in the corresponding entry in the settings file, even the notation:  
j5board:require("johnny-five").(new Board({port: "COM5", repl:false}))  
did not function. I think this should be changed in node-red.  
However I found a workaround:

1. insert in Class Board in johnny-five Board.js the following function:  
static create(options = {}) {  
return new Board(options);  
}
2. change the settings entry to:  
j5board:require("johnny-five").Board.create({port: "COMx", repl:false})

I am not sure about conformity and efficiency concerning the class handling in javascript, but at least the workaround functions.  
Nevertheless should node-red allow the new keyword in the settings file.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 August 2021 11:10 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654/2 "2021-08-12T11:10:33Z")

</div>

You can simply add a const at the top of the settings file, create your instance (using new) then set the settings entry to your const variable.

Above `module.exports = {` ...

```auto
const j5 = new blahblahblah(x,y,z);

```

Inside `module.exports = {` ...

```auto
   j5board:j5,

```

---

<div class="post-metadata">

**Author:** ![JK40105](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jk40105/32/38882_2.png) [@JK40105](https://discourse.nodered.org/u/JK40105)\
**Post date:** [12 August 2021 12:44 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654/3 "2021-08-12T12:44:43Z")

</div>

Thank you very much for your prompt help!

However const j5b = new require("johnny-five").Board({port: "COM5", repl:false}); did not function, but

const j5f = require("johnny-five");

const j5b = new j5f.Board({port: "COM5", repl:false}); before module.exports does function.

Thanks again, this is clearly a better solution.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 August 2021 13:40 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654/4 "2021-08-12T13:40:39Z")

</div>

Yes, of course you need to do the require first 👍 (I should have been more explicit sorry)

---

<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 October 2021 13:41 UTC](https://discourse.nodered.org/t/johnny-five-version-2-1-under-windows/49654/5 "2021-10-11T13:41:38Z")

</div>

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