If you want a simpler way of running Node-RED robustly with the benefits of auto-restart, log management, etc, I would recommend using PM2 and starting that using Task Scheduler.
One thing to note is that if you want to run node-red before you have logged in with your user account, you will have to give scheduler your password. A better alternative is to allow PM2 to start under the SYSTEM account now that you know a bit more about how it works
Alternatively, consider setting up another local user that does not have local admin rights and run PM2/node-red under that. That could be a bit more complex if you need access to specific shared local resources but at least avoids a messed up flow (or malware compromise) messing up your main account.
PM2 does have some overheads as it is itself a node.js application. But it is quite powerful. For example, you can configure it to "watch" key files/folders and automatically restart node-red. I use this feature to make development of node-red nodes a lot nicer.
I don't believe it should be the first choice. It is an optional component after all and really designed to help people migrate to Windows
Node.js apps work fine on Windows natively and many people just want to run node-red as an app anyway and PM2 is great to facilitate that. The main issue is that the average Windows user never has to get to grips with running things as services so doesn't understand the details. Also, relatively few of us (myself included generally) don't run node-red as a service since a Linux server is generally a lot cheaper for that kind of thing.
i couldn't agree more with you on this, having happily experienced NR on a raspbian since 2018.
I was somehow forced to go windows because I need to use ETS 6.x ( the official KNX project Management) that, unfortunately, runs on Windows only (not even virtualized according to the official doc).
I learnt from this thread about the promising WSL/systemd route. For the time being I will run NR from command node-red as a current user process and not as a system owned service that proved so problematic.
To be honest with you I have not understood whether NR as a system owned service can or can't have access to the local images referenced inside a template node. From the experience I had I understand it can't, but officially nobody told me.
I'm asking that for the benefit of future NR users on windows platform so they can be warned about this limiting issue should they read this post.
Thank you again for your patience and support.
There are two issues there. Firstly the user running node red (SYSTEM in this case) must be able to access the files. Secondly, httpStatic must be set correctly. It is likely that the settings.js file that was being used is not the one you edited. Had you edited the one actually in use it may well have worked.
[Edit] The best solution is to configure NSSM to run node red as the correct user, with the correct working directory, as I think was suggested earlier in the thread.
I've also done some reading up of Docker on Windows. Seems like ALL of the ways of running standard containers on Windows all require WSL as well.
Will do some more research on running node.js apps as Windows services to see if there are better options than nssm since last I looked. Native is pretty much always going to be better than virtualised on Windows desktops I think.
Yes, that is still the recommendation - at least for now.
To clarify I recommend using a specific user id to run node-red if you wish to have it permanently running in the background. SYSTEM has a lot of access and might be abused. This is in line with my security recommendations for running node-red under Linux too.
If you simply want to run it periodically as a Windows app, I recommend using PM2 to run it under your current user id - you can use the package.json in your userDir folder to define some npm scripts to start/restart and show logs. You can also use a watch list for auto-restart after key file changes.
The other approach is to turn on IIS which is Windows' web server and it can be used as a reverse proxy. There is an extension for it that lets it manage node.js services directly. I need to dig out the name of that.
I stubbornly tried to keep SYSTEM account before eventually giving up. I repeatedly checked, via Windows folder permissions dialogue, that SYSTEM user had all possible rights on C:\domotica folder. I then edited settings.js in "C:\Users\rober\AppData\Roaming\npm\node_modules\node-red\settings.js” (the only other settings.js to be found in the machine) enabling httpStatic to "C:\domotica”, closing and restarting the machine and therefore the process. Still the images were not accessible. BTW, following your suggestion, I changed that folder position as well and edited settings.js accordingly.
According to my findings it might be on or the other:
node-red launched as a service by SYSTEM is not using settings.js at all
node-red uses a settings.js located in an user not accessible position so it cannot be edited and enable HTTPStatic.
node-red launched by SYSTEM is somehow sandboxed in his service and has not the rights to the folder we otherwise see from folder permissions.
In any case the issue turned out too complex for my forces and experience on windows platform and I eventually gave up.
Now I’m happily seeing my images with template node and the only way I found was launching node-red with its command “node-red” ad a current user process.
One final favour, can you confirm that the user flows goes in "C:\Users\rober.node-red\flows.json”? Do you know where all added installed nodes go? I would backup what is necessary for a fast restore in case of a disaster.
Look in the startup log to confirm which flows file it is using.
By default the installed nodes go in the node_modules subfolder of the same folder the flows are in, so usually .node-red/node_modules. However generally you should not back that up as it can be very large and contains compiled code that may not work when you restore it (if nodejs has been updated to a new major version for example). The definitions of which nodes to installed is in .node-red/package.json and package-lock.json. Generally one should back up the whole of the .node-red folder except for node_modules. Then if one has to restore, go into the .node-red folder and run npm install
which will look in the package files and install and recompile everything you need.