# Node-RED lints when developing nodes

**URL:** <https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946>\
**Category:** Developing Nodes\
**Created:** [2 August 2024 07:30 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946 "2024-08-02T07:30:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 07:30 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/1 "2024-08-02T07:30:33Z")

</div>

Is there a way to get proper linting when developing nodes? I have no type information about the 'RED' variable that is used with the Node-RED functions.

Is there some dev dependency I can add? Or something else I need to configure.

I know my way around javascript the language, but the whole ecosystem is still very unclear to me.

I use vscode as my editor if that helps.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [2 August 2024 08:10 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/2 "2024-08-02T08:10:12Z")

</div>

There is `@types/node-red` which you can install as devDependency.

After installation vscode will be able to search for types.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 August 2024 08:19 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/3 "2024-08-02T08:19:49Z")

</div>

> [@GogoVega](#):
>
> There is `@types/node-red` which you can install as devDependency.

Not sure that gets updated much does it?

I _think_ that the current info is in the node-red package itself. so you might need to install it as a dev dependency for each node you are developing.

Personally, I don't like to do that so UIBUILDER has its own typedef defined. That includes some basic node-red stull but also all of the extended definitions of my own nodes including runtime and editor.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b1a0763581a5e3036e1bc029ab1a3e80823db7c.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/315f1d7da33451a3e34f6768c86ce1b0694e0c6c.png)

Not perfect but useful to me at least.

Examples of use in a node runtime:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd7f96049c128c53e372d087b7629408a1e3712b.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/3412c323abc80a4e86716bd4733cb827a2fa2189.png)

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [2 August 2024 08:40 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/4 "2024-08-02T08:40:15Z")

</div>

> [@TotallyInformation](#):
>
> Not sure that gets updated much does it?

I haven't checked for v4 but it was up to date last time I looked at.

I know what usually changes is the `RED.util` part.

I think Nick would like NR to be (more) typed but it takes time (if I remember correctly the discussion).

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 09:04 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/5 "2024-08-02T09:04:28Z")

</div>

installed it,  
RED still has type: any, and no method signatures.  
So that doesn't seem to work or I'm missing something, I did npm install after adding it to my package.json under "devDependencies".

It gives some audit warnings though

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 09:05 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/6 "2024-08-02T09:05:21Z")

</div>

I tried adding "node-red" as a devDependency but this didn't seem to help unfortunately

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [2 August 2024 09:12 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/7 "2024-08-02T09:12:55Z")

</div>

You can use as follow:

```js
/**
 * @type {import("node-red").NodeAPI} RED
 */
var RED;

/**
 * @param {import("node-red").NodeAPI} red
 */
function random(red) {}

```

It use the `@types/node-red` package

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 09:13 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/8 "2024-08-02T09:13:34Z")

</div>

Okay I found an example and they just use "RED.nodes as any" rip

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [2 August 2024 09:16 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/9 "2024-08-02T09:16:02Z")

</div>

Do you use JavaScript or TypeScript? `as any` is a TS thing.

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 09:17 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/10 "2024-08-02T09:17:05Z")

</div>

Yes! that seems to work, thanks a lot!

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 09:17 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/11 "2024-08-02T09:17:54Z")

</div>

Currently my nodes are still vanilla javascript, but I am testing the waters with typescript

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 August 2024 10:38 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/12 "2024-08-02T10:38:10Z")

</div>

> [@GogoVega](#):
>
> I think Nick would like NR to be (more) typed but it takes time (if I remember correctly the discussion).

Anyone is welcome to use the definitions in uibuilder. 😁

> [@GogoVega](#):
>
> I haven't checked for v4 but it was up to date last time I looked at.

Perhaps it is. Somewhat confusing that it's version doesn't match the Node-RED version:

> **[@types/node-red](https://www.npmjs.com/package/@types/node-red)**
>
> TypeScript definitions for node-red. Latest version: 1.3.5, last published: 5 months ago. Start using @types/node-red in your project by running \`npm i @types/node-red\`. There are 18 other projects in the npm registry using @types/node-red.

It is currently v1.3.5

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 August 2024 10:45 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/13 "2024-08-02T10:45:19Z")

</div>

> [@SpieringsAE](#):
>
> I tried adding "node-red" as a devDependency but this didn't seem to help

You can always do what I do and add a `typedefs.js` file in the root of your package. I just use JSDoc definitions in there, VScode is quite happy with that.

Feel free to use the file in the uibuilder package as a starting point.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 August 2024 10:50 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/14 "2024-08-02T10:50:04Z")

</div>

> [@SpieringsAE](#):
>
> still vanilla javascript, but I am testing the waters with typescript

I have to say - just my personal opinion of course - that the reason I switched to using Node.js from PHP over a decade a go was that I didn't want to spend time learning multiple languages and I already had to know JavaScript for the browser.

So for me, using Typescript would be a serious backwards step. JavaScript with VSCode and decent use of JSDoc definitions seems to do everything I would want from Typescript without having to write double the number of files with significantly more complex grammar (JS is bad enough).

---

<div class="post-metadata">

**Author:** ![SpieringsAE](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/spieringsae/32/87710_2.png) [@SpieringsAE](https://discourse.nodered.org/u/SpieringsAE)\
**Post date:** [2 August 2024 10:55 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/15 "2024-08-02T10:55:54Z")

</div>

its already too late for not learning multiple languages haha, I have to use matlab, c, zig, rust, python,javascript, bash on a day to day base. Okay zig and rust are not mandatory, I wormed those in but yeah, I really like statically typed languages, I've tried some typescript and so far liking it a lot more than javascript.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [2 August 2024 12:26 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/16 "2024-08-02T12:26:34Z")

</div>

Fair enough and if you use C/C++ I suspect that makes TypeScript rather more acceptable.

Nobody doubts that JavaScript is a fairly horrid language. But it is still infinitely nicer to use (in my highly biased opinion 😀 ) than C/C++.

To be fair, some of JS's horrors lie not in the language but in the HTML API's some of which are appalling.

But hey, as I say, I can't avoid JS and after so long, I can't be bothered to learn a new language - I'm not a professional developer after all (used to be, a very, very long time ago now).

If I were going to learn (re-learn actually) another server-side language, it would be to learn more Python again. I know just enough C/C++ to be able to do stuff on Microcontrollers if I have to. I use BASH and PowerShell where I need to, thankfully not too often. I do miss FORTH and APL though 🤣

---

<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:** [16 August 2024 12:27 UTC](https://discourse.nodered.org/t/node-red-lints-when-developing-nodes/89946/17 "2024-08-16T12:27:23Z")

</div>

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