1

I want to automatically start my node server on the VM's reboot using the following batch script

@echo off
cd /D c:/Application Services/servers/dashboard/server
echo Starting Dashboard Server In Production: port 8446
npm run prod

the "prod" script is defined as

 "prod": "set PORT=8446&&set NODE_ENV=production&&node --no-warnings ./bin/www"

When run on it's own, the batch script works and localhost:8446 gives a response

When I start the service I created with NSSM the script doesn't seem to run here's how I created the service

nssm install DashboardService

The GUI popped up and I selected the path to the batch file

This is the service editor but everything was the same on creation

The service installed and started successfully but localhost:8446 didn't give back a response indicating to me that the service didn't execute the batch script

There's another service that is just like this one already on my system and I checked to make sure my service was set up the exact same way. I changed my service to execute the batch script the working service was executing and my service successfully ran that batch script so it's not a problem with nssm or the service manager but with the batch script.

I based my batch script off the working:

@echo off
cd /D c:/IOEServices/node-servers
echo Starting GraphQL Server 
node src/index.js

So my question is, why isn't the batch script executing when prompted by services and starting the node server?

Paul Sender
  • 376
  • 2
  • 19
  • Why not use the proper name and full path, instead of `npm`, for example `Call "C:\somewhere\npm.cmd" run prod`. Also change your 'nix path separators to Windows ones, and doublequote the path, as it contains a space character, e.g. `CD /D "C:\Application Services\servers\dashboard\server"`. Please do not however expect that you can use any process as a service, if you want a service write a service excutable. – Compo Jul 22 '20 at 16:10
  • I followed your suggestions, my batch file now looks like ```@echo off cd /D "C:\Application Services\servers\dashboard\server" echo Starting Dashboard Server In Production: port 8446 "C:\Program Files\nodejs\npm.cmd" run prod``` and while it works by running the batch script alone, it still does not execute when the service goes to run it – Paul Sender Jul 22 '20 at 16:17
  • I cannot help you with your issue, because I do not agree with pretending a program and/or script is a service, when it clearly isn't. My advice has fixed your code, _(despite the fact, I used the `Call` command, `Call "%ProgramFiles%\nodejs\npm.cmd" run prod"`)_, which is what this site is supposed to be for. – Compo Jul 22 '20 at 16:23

0 Answers0