Node RED v4 : Single File Executable

marcus-j-davies
Sat, 06 Jul 2024 16:26:08 +0000
Share Your Projects

Afternoon,

It's Back!!
Single File Executable for Node RED v4 (With the option of embedding your flows)

Some History:

A while ago, I posted a guide on how to create an SFE :
See Node-RED Standalone Executable - #12 by marcus-j-davies

This quickly become incompatible shortly after, due to ESM being used and various other changes in the core, so I have spent many many hours in getting this working... and

Today:

I share a new guide:

Easier

Node RED v4

Allows embedding a flow (i.e protecting your IP)

Allows hiding your logic

It contains the following routines:

Converting the ES Modules to CommonJS (got for example, used by the http-request node)

Bundling Node RED to a single file

Patching Node RED and other source files, where needed

Packing them into an executable

You don't need to do the above yourself

What's more, this new guide has an easier way to embed your flows, that are loaded from within the executable.

Let's Begin

Create a Folder called NR (this name is important)

In this folder, download the following files

build.js

main-source.js

package.json

From : Node Red V4 - SEF (Single Executable File) · GitHub

Execute npm install from within NR

Adjust the Settings "file"

The Node RED settings object, can be found in main-source.js
you will see some hackery here - don't mess with it, such as the userDir redirect

Only change flowFile if it is different.

You MUST change secret !

disableUI should be set to true (IF) embedding the flow.
The editor security routines, seems to want to write to userDir, so just disable it.

NOTE: This should be done just before compiling the executable
(not during design) - see below

you can (I think) treat this like the standard settings.js file

Then

If you DON'T want to embed a flow [ userDir : {PWD}/Home ]

npm run-script build

npm run-script package

If you DO want to embed a flow [ userDir : Embedded ]

npm run-script design

Design your flow, publish, install nodes etc etc

Terminate once you're done

set disableUI to true (if you want to hide the Editor)

npm run-script build

npm run-script package

Congratulations!

You now have a Node RED executable in ./build/dist
as well as embedded nodes and the flow being run from the embedded flows file, if you decided to.

Lastly,

I have spent sometime getting this right and working, but I more than happy for contribution here.
I'm sure it can be optimised in areas!

I developed this toolkit on OSX, but can't see why it wouldn't work on other platforms.
And do note: the executable is built for the platform this toolkit is run.

Note : I have favoured Node 20 in these scripts

Please do comment and add your input

Enjoy (now I am off for a gin )

60 posts - 6 participants

Read full topic