This monorepo can be used to develop node-red nodes in typescript with VSCode
install node >= 16.10 install yarn https://yarnpkg.com/getting-started/install install yarn workspace tools plugin https://yarnpkg.com/api/modules/plugin_workspace_tools.html
i also recommend to update to the latest version of yarn: yarn set version stable
at the root directory do:
- use
yarn installto setup everything. - perform
yarn build yarn testto see if the node tests run successfully
- create your nodes in
packages/nodes/yourNodeName - make sure you copy the
tsconfig.jsonandtsconfig.dist.jsonfrom the root into that folder. - create the following package.json inside and replace
$YOUR_NICKand$YOUR_NODE
{
"name": "@$YOUR_NICK/$YOUR_NODE",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"clean": "rimraf dist",
"build": "yarn build:tsc && yarn build:copy-html",
"build:tsc": "tsc -p tsconfig.dist.json",
"build:copy-html": "node -r ts-node/register ./../../../build-scripts/copy-html.ts",
"build:watch": "tsc -p tsconfig.dist.json --watch",
"test": "yarn jest --verbose"
},
"node-red": {
"version": ">=1.3.7",
"nodes": {
"$YOUR_NODE": "dist/nodes/$YOUR_NODE/$YOUR_NODE.js",
}
},
"engines": {
"node": ">=v12.0.0"
},
"keywords": [
"node-red"
],
"devDependencies": {
"@types/node-red": "^1.2.1",
"@types/node-red-node-test-helper": "^0.2.2",
"node-red-node-test-helper": "^0.2.7"
},
"repository": {
"type": "git",
"url": "git+https://github.com/$YOUR_NICK/$YOUR_NODE.git"
},
"bugs": {
"url": "https://github.com/$YOUR_NICK/$YOUR_NODE/issues"
},
"homepage": "https://github.com/$YOUR_NICK/$YOUR_NODE#readme",
"author": "$YOUR_NICK",
"license": "MIT"
}
- open your custom node project set breakpoints and use vscode debugger (F5) to start the runtime (node-red) with your nodes.
- navigate to your node-red instance (default: http://localhost:1880)
- create your flow with your nodes.
- inject messages in your flow.
- you can debug your code with your breakpoints
The runtime will not delete the flows.json.