# Running on Windows (again)

I have installed Node-red on Windows 10 and used Task Scheduler to make it start at boot:

It does start but I get a console window on the desktop:

I want it to run not secretly but inconspicuously in the background.

Can the console output be sent to a file instead of the screen?
Can it be ditched entirely cf /dev/null on Linux?
How do I prevent Node-red output from filling up my small ssd hard disk?
Is it a setting in Task Scheduler? in node-red.cmd?

Sorry, I know nothing about Windows scripting!

Look in the node red docs on running in Windows and I think it will tell you ways to run it automatically on boot.

Well yes it does tell you how to run it automatically on boot.
I thought I had explained that I had got it to run automatically on boot, but it shows the [npm?] console window on the desktop, and I want to try and get rid of it.

The [only?] relevant bit of the documentation is this

You can check for failures by looking in the event log. If you want to access to the logs when running this way, you should amend the node-red.cmd file to redirect std and error outputs to a file (creating an alternative startup file would be better so that it isn’t overwritten on updates).

So I tried appending parameters to the task scheduler action  > NUL 2>&1 which resulted in the npm console showing up but empty. I believe closing this window kills Node-red, which is undesirable.

Then I tried changing node-red.cmd to this

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\node_modules\node-red\red.js > NUL 2>&1" %*


ie  > NUL 2>&1 after the call to red.js.

The result is a console window opens momentarily, but Node-red is not running.

I am sorry if you think this is a trivial issue easily solved by a moment's googling.
I have tried that and I'm puzzled by the absence of anyone else reporting this popup on the desktop. It makes me think I may have made a mistake installing.

The fact is that ever since I became a reluctant Windows user I have installed programs with the Windows installer. It hasn't always worked, it's often been infuriating but it has always been consistent. Except when I install Node-red.
So I have never had to learn the syntax of a file like node-red.cmd.

Why is installing Node-red so different from installing (for example) Libre Office or Photoshop?

For such cases I use the tool nircmd from nirsoft in combination with the execmd parameter.

P:\ath\to\nircmd.exe execmd C:\path\to\node-red.cmd

1 Like

There is also a tool that converts an executable startup to a Windows service, that would also fix the issue.

Thanks for the suggestion steff.

I have a flow I made that can both create, list, and uninstall services on Windows.
Perhaps it could be of use:

[{"id":"3ac164651f62cdbe","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"6eebe74c856731e4","type":"function","z":"3ac164651f62cdbe","name":"create new service","func":"var Service = nodeWindows.Service\n\n// Create a new service object\nvar svc = new Service({\n    name: 'Put a name here',\n    description: 'Put a description here.',\n    script: 'C:\\\\Full\\\\Path\\\\app.js',\n    //nodeOptions: [\n    //    '--harmony',\n    //    '--max_old_space_size=4096'\n    //]\n    workingDirectory: 'C:\\\\Working\\\\Directory\\\\'\n    //, allowServiceLogon: true\n});\n\n// Listen for the \"install\" event, which indicates the\n// process is available as a service.\nsvc.on('install', function () {\n    svc.start();\n    node.send({ \"payload\":Service has started from install});\n});\n\nsvc.install();","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"nodeWindows","module":"node-windows"}],"x":270,"y":100,"wires":[["2470a9503c1eb4f4"]]},{"id":"311658685aef434c","type":"inject","z":"3ac164651f62cdbe","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":90,"y":100,"wires":[["6eebe74c856731e4"]]},{"id":"2470a9503c1eb4f4","type":"debug","z":"3ac164651f62cdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":100,"wires":[]},{"id":"0910a6d35a0820de","type":"function","z":"3ac164651f62cdbe","name":"list services verbose","func":"var wincmd = nodeWindows;\n\nwincmd.list(function (svc) {\n    node.send({\"payload\":svc});\n    node.done();\n}, true);","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"nodeWindows","module":"node-windows"}],"x":280,"y":260,"wires":[["4904a3fe2c5f9f16"]]},{"id":"ed4c90a8b83430b0","type":"inject","z":"3ac164651f62cdbe","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":90,"y":260,"wires":[["0910a6d35a0820de"]]},{"id":"4904a3fe2c5f9f16","type":"debug","z":"3ac164651f62cdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":260,"wires":[]},{"id":"01ed7832a814ff87","type":"function","z":"3ac164651f62cdbe","name":"kill process by PID","func":"var wincmd = nodeWindows;\n\nwincmd.kill(msg.pid, function () {\n    node.send({ \"payload\":Process ${msg.pid} has been Killed});\n node.done();\n});","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"nodeWindows","module":"node-windows"}],"x":270,"y":320,"wires":[["f4ed3ef1a87c4117"]]},{"id":"fbb851a46cce76e7","type":"inject","z":"3ac164651f62cdbe","name":"","props":[{"p":"pid","v":"","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":320,"wires":[["01ed7832a814ff87"]]},{"id":"f4ed3ef1a87c4117","type":"debug","z":"3ac164651f62cdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":320,"wires":[]},{"id":"0350d10dd71106ad","type":"function","z":"3ac164651f62cdbe","name":"list services","func":"var wincmd = nodeWindows;\n\nwincmd.list(function (svc) {\n node.send({\"payload\":svc});\n node.done();\n}, false);","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"nodeWindows","module":"node-windows"}],"x":250,"y":220,"wires":[["db5f09e69d76fc08"]]},{"id":"8f0a9279c87c9b33","type":"inject","z":"3ac164651f62cdbe","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":90,"y":220,"wires":[["0350d10dd71106ad"]]},{"id":"db5f09e69d76fc08","type":"debug","z":"3ac164651f62cdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":220,"wires":[]},{"id":"1338123e6a74df57","type":"function","z":"3ac164651f62cdbe","name":"uninstall service","func":"var Service = nodeWindows.Service\n\n// Create a new service object\nvar svc = new Service({\n name: 'Put a name here',\n script: 'C:\\\\Full\\\\Path\\\\app.js'\n});\n\n// Listen for the \"uninstall\" event so we know when it's done.\nsvc.on('uninstall', function () {\n node.send({ \"payload\": Uninstall complete.});\n node.send({ \"payload\": The service exists,${svc.exists}});\n});\n\n// Uninstall the service.\nsvc.uninstall();","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"nodeWindows","module":"node-windows"}],"x":260,"y":160,"wires":[["b93a4bd95dff2ca8"]]},{"id":"452b9cb84794a9fd","type":"inject","z":"3ac164651f62cdbe","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":90,"y":160,"wires":[["1338123e6a74df57"]]},{"id":"b93a4bd95dff2ca8","type":"debug","z":"3ac164651f62cdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":160,"wires":[]},{"id":"9209aa14249a8ac3","type":"comment","z":"3ac164651f62cdbe","name":"Run app.js as a service in Windows","info":"","x":280,"y":40,"wires":[]}]


However, it does require the external module node-windows to be installed.

You just need to specify an absolute file path, name, and description in the functions.

Have you tried the command in cmd.exe or PowerShell and does the command return error messages?

Maybe there are missing quotation marks around the path if there is a space in it.

Otherwise, the solutions from @TotallyInformation (NSSM - the Non-Sucking Service Manager) and from @HaroldPetersInskipp are of course also worth a try.