If you want to get net wlan show profiles output no matter if it fails or not, you can use either asynchronous version of exec. The callback will have stdout set.
Or you can catch exception and get stdout from there. Something like:
let nestsh_output;
try {
netsh_output = execSync('netsh wlan show profiles');
} catch (ex) {
netsh_output = ex.stdout;
}
That said, I don't see any issue with Node.js here, so I will close this. If you think that there is a bug here feel free to reopen the issue. If you have more questions about how to do stuff in Node.js, check out https://github.com/nodejs/help.