Setup a own Node-RED Dev Environment in 5 min.
This is a step-by-step tutorial to setup an embedded Node-RED instance for node development with Visual Studio Code for Windows OS. Of course you can use any other IDE/Editor/OS of your choice.
This is not an introduction to Node-RED. If you are not familiar with Node-RED I advice you read the articles of Stephen Keep on medium.
This guide is not written for beginners. The tutorial is basically around node-red-embedded initiated by Julian Knight (TotallyInformation) and extended with some convenient stuff by me. You can fine the repository here:
node-red-template-embedded - A template project for running Node-Red in "embedded" mode which is great if you want to…github.com
The README will give you a lot of more information on the embedded mode of Node-RED
You will need setup NodeJS and npm for node-RED, so install it on your target where you are planning to run Node-RED. Follow the section (only) “Install NodeJS” from the Getting started Guide here.
You do not need to install Node-RED at this step, we will come to this later.
For local and remote development I recommend to use Microsoft’s Visual Studio Code. It is an intelligent code editor incorporating node.js debugging facilities by using the Chrome debugging features.
To setup a node-RED project just download the following archive and extract it.
Open the extracted folder with Code (the short name for Visual Studio Code), open the terminal via
View > Terminal and enter the command:
This will build up your node-RED development environment and take some time. After this you launch the development version of Node-RED by executing
npm run debug
That’s it. To debug your js codes, e.g. of your own node-red contributions, you will just hit F5 on your keyboard. This will launch node-RED and attach the debugger to the process.
Maybe you want to run Node-RED run on another machine, a VM or a RaspberryPI. You can setup Node-RED like described above, but you do not want to miss your local development tools like VSCode. No problem. This here is for Windows but principle is adoptable to other platforms.
We assume you can get read/write access to your remote Node-RED installation via SSH/SFTP. Download and install WinSCP — a tool which let you manage your remote files.
Start WinSCP and create a connection to your remote. You should see the exptected files.
Then press CTRL-ALT-P (a shortcut to the Preferences) to bringup the settings dialog. Go to “Editors” and add an entry for VSCode like pictured below.
This will open JS, HTML and JSON files remotes by copying them to a local temporary directory and open it with VSCode. When you modify the file WinSCP will watch for changes and upload it automatically to your remote host. This way you can edit remote files locally.
When you are starting Node-RED on the remote via
npm run debug it will be started with nodemon. This is tool which will look for changes on program files and will restart Node-RED if needed.
So this way, everytime you make changes to your code, remote or locally, Node-RED will be restarted.
Like debugging locally you can debug remote with a difference debugger configuration for VSCode: Just put in the right host, port and directories and you can even debug your remote Node-RED instance.
Note: It is more fun to debug locally running code