# Running on Windows (again)

**URL:** <https://discourse.nodered.org/t/running-on-windows-again/65236>\
**Category:** General\
**Created:** [17 July 2022 20:06 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236 "2022-07-17T20:06:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 July 2022 20:06 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/1 "2022-07-17T20:06:13Z")

</div>

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

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58f0027f3f89bd8a1c9c848118f8bccf8b9d65b3.jpeg)

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

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4dac5e0ed54539ec90167711e6cad0396700bc2.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2022 20:39 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/2 "2022-07-17T20:39:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 July 2022 21:47 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/3 "2022-07-17T21:47:30Z")

</div>

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

```auto
@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?

---

<div class="post-metadata">

**Author:** ![steff](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steff/32/80733_2.png) [@steff](https://discourse.nodered.org/u/steff)\
**Post date:** [18 July 2022 08:19 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/4 "2022-07-18T08:19:19Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 July 2022 13:05 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/5 "2022-07-18T13:05:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 July 2022 00:50 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/6 "2022-07-23T00:50:22Z")

</div>

Thanks for the suggestion steff.

I tried it but couldn't get it working before I had to return to Europe.

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [23 July 2022 01:01 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/7 "2022-07-23T01:01:14Z")

</div>

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

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![steff](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steff/32/80733_2.png) [@steff](https://discourse.nodered.org/u/steff)\
**Post date:** [23 July 2022 06:58 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/8 "2022-07-23T06:58:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 September 2022 06:58 UTC](https://discourse.nodered.org/t/running-on-windows-again/65236/9 "2022-09-21T06:58:17Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
