How to debug no console app with nssm

I needed to debug an application that is run as a windows service registered by nssm. The behavior that I wanted to investigate occurred only in a production environment. So, I had to debug it without VSCode.

It is a Node.js application and thus I could check the source code but I didn’t know how to debug it without a console.

Solution

If nssm can link Stdout to a file, we can debug with console.log().

The official page explains how to set it up.
It is explained in I/O redirection part.

We need to change the registry for it.

1. Open HKLM\System\CurrentControlSet\Services\servicename\Parameters
2. Add AppStdout there
3. Set a file path for the log (e.g. “D:\nssm-app.log“) to the value

If the service name is “FileWatchService“, the registry is HKLM\System\CurrentControlSet\Services\FileWatchService\Parameters.

Then, all console log output is written to the file.