I see, and your method allows you to move the standalone executable to a raspberry pi that doesn't have node-RED installed?
Providing - the target platform is of the same platform your run
pkg will embed the Node runtime of the platform
you can use this, to ensure the correct executable
pkg . -t host <- will use the host platform for the binary output. But I think not including -t will still produce a Linux executable.
The executable will still create the $USER/.node-red dir, but you can pass the normal arguments to it, if you wanted to ship a flow with your executable
Good to know. I don't want to sound like a pest, but could you show me an example of a complete
package.json file after you have made your modifications?
I can soon, not at a computer right now.
Ok I would appreciate it. Thank you for what you have already shared as well.
Start to Finnish (I have just tested this on OSX)
Create working directory, install Node RED
npm install node-red
Hard Install some nodes (using dashboard as example)
npm install node-red-dashboard
Modify package.json (NodeRED/package.json)
/* Before */
/* After */
Build Binary (it will also embed any nodes you installed in step 2)
pkg . -t host
Run Binary (or move it to a new system) <- only binary is needed
Node-RED --userDir /some/dir
There are pros and cons to hard installing nodes.
- No need to transport large
- Can't remove or update hard installed nodes (as they are embdded)
So hard installing nodes is optional, but for nodes you need, you will need to install them normally if not embedding them
Great! This is very helpful. The missing piece has always been the part of
package.json to start node-RED. All the examples I have seen want a section called "main" and it usually contains
index.js or something similar. I believe this is more of a Node.js application. It seems like the "bin" section takes care of that.
I am going to try to get this to work using my current install of Node-RED and the Projects feature. If I am not able to get it to work, I will follow your instructions precisely. Either way, I will post my results.
I'm also still interested in the electron solution if anyone has any experience they'd like to share, or can point me to an explanation of how it works?
One more question I thought of, if I wanted to build an executable to run on Windows, but I developed it on a Raspberry Pi, is it really as easy as just changing the target section of the
it is possible by setting
win64 (I believe) - you will need to research.
I don't specify it In the package file
But do be cautions:
Some Node modules are "compiled" during install - so they will not be binary compatible
(Even if the resulting "parent" binary that encapsulate it is)
Here is the result from my steps (I have deleted all folders) - to remove the templated install: for proof I guess
I should be using --userDir not --userDIR
It turns up with an Internet search.
Can you point me to some specifics on how to do this? I would like, at least, to enable projects and open a port for mqtt. I have pulled the docker image into VS Code, but don't know what to do next.
I don't want to hijack this thread, but this is a neat solution. Is it also possible to include a flow file+credentials+settings and having it execute immediately with (customized) settings ? ie. I want to hide the gui and just have a flow running directly from the executable.
Yes you can
But there are a few things to watch for and do.
You wont be able to make changes to the flow, trying to
deploy will complain of a Read Only File System (See my image)
You need to set the flows file and settings file as augments, when running the executable
The virtual file system starts at
With all that in mind...
Lets assume we are working in a directory called NR
The folder in which you installed Node RED (I.e your working directory) add a folder of say config
Add this folder to the assets section of package.json
"assets": ["./node_modules/**/*.*", "./config/**/*.*"]
Start node red normally to create your flows,
BUT pass in an arg of
--userDir <Location of Config Dir>
Run the normal pkg command
To run the executable and have it use the embedded settings file and flows....
Node-RED-Executable --settings /snapshot/NR/config/settings.js /snapshot/NR/config/flows.json
Note: you will still need to set a
userDir or let it use default, as Node RED will try and create it each time, and if setting
userDir to an embdded location, it will crash trying to create the Dir
Seems that it IS possible to have a container to host a writable file system. But any changes are written to the host filing system rather than the container (since containers are mostly read-only).
You can use an overlay filing system to do that in Linux. I doubt it is possible in Windows.
I only use Docker for the most basic of things so I'm no expert but some searching turned up a number of posts about this.
Maybe start with this backgrounder: What are Docker Storage Drivers and Which Should You Use? (howtogeek.com)
Sorry for my absence. I have circled back around to this project and have some questions.
- Am I right in assuming if I have an already developed Node-RED application I can just replace the flows.json file with mine into the directory that gets created? Or is it usually better to develop after I've followed step 1?
- If I use something like
node-red-contrib-ui-mediaa folder called "ui-media" gets created to use your uploaded media. Should this work the same?
- I'm currently using a folder in my Projects directory called "audio" to store some .wav files and I reference their location in some
read-filenodes. Do I need to add them as dependencies in the package.json file? Are there any other locations that need to be aware of this?
In an effort to try other solutions as well and report on them, I have tried to follow the steps from this ReadMe GitHub - dceejay/node-red-project-starter: This is a template for a Node-RED project meant to be run in local mode but I ran into issues with require() not being supported. I followed some articles that say to change require() to import() but then I got an error that I can't use import outside of a module. The next solution I found said to add a line to my package.json to change type from "git" to "module" but this didn't help. Has anyone used this successfully? Is this option of packaging similar enough to the 'pkg' method discussed above? Any advantages?
I noticed GitHub - dceejay/electron-node-red: Electron Node-RED template appears to be more detailed, but also more involved. I will try it as well, could someone share their experience with it, any pitfalls to avoid, or suggestions?
Did you take a look at my alternative installer?
It helps you create a stand-alone folder structure that includes node-red and a data sub-folder that is your userDir so everything is within a single master folder.
@TotallyInformation I had not looked at this until now. If I understand correctly, your "alternative installer" and dceejay's "node-red-project-starter" are essentially trying to accomplish the same thing?
- Once this is installed can I copy my 'flows', 'flows credentials', and any other files to the new folder structure, or would I need to export and import within the editor to make sure things get put in the proper places?
- Can I install additional nodes from the palette manager, or would I need to use
- Would I need to move the entire directory to the new Pi once I'm ready to deploy? Or would it be beneficial to still create an executable/binary?
Sorry for all the questions, I have a bad habit of asking too many questions before I get started on something when half of them could be answered if I just get started...
You can simply duplicate the whole thing. - ish.
Either will work fine.
You need everything. However, there is one slight issue. If you set up on one platform and then move to a different one - e.g. PC to Raspberry Pi - you need to not copy over the
node_modules folder because some of the installed packages won't work. They also tend to be massive and not worth copying anyway. Instead, copy everything except those folders and do an
npm install in each of the master folder and the data folders (and the uibuilder folder if you are using that). The respective
package.json files contain everything needed to reinstall the correct packages.
This sounds great. I want to rephrase my first question as it was kind of vague. Once I complete the install process, what is the best way to move an existing project to the standalone install? I.e. I have already completed a project using a standard Node-RED install with the projects feature, and I want to move it to the standalone setup?
Also, when I want to start a new project using the standalone setup, would I just copy the master directory to a new directory, and then change the flows? Or would starting the process over be the better option?
"best" is probably rather subjective
If you are copying to a similar platform (e.g. Wintel -> Wintel) you can go ahead and do a straight copy.
However, if you are doing it regularly, I would recommend creating a script. Details of that are going to depend on your platforms. I'd be happy to add some scripts to the alternate installer repo though if you can come up with a decent one. And happy to help if you have some more detail about the source/target platforms.