node.jswindows-serviceshttpservernssm

npm http-server as a Windows Service


I am using http-server to host one of my local folders: enter image description here

enter image description here

http-server ./

As you can see I downloaded nssm.exe. I am wondering how I can make this http-server command as service so I can permanently host this folder even when computer restarts? One of the suggestions I found is to use nssm but I am not sure how I can do it. I type this in my cmd:

nssm install httpserver

and then get:

enter image description here

now how to start the http-server ./ command ? Where I should type it and how?

Also if there is easier way to do it without nssm I am open to see it.


Solution

  • I tried it by taking the following steps:

    1. Creating a batch file(script.bat) in the directory with the command:

      http-server .

    2. Adding npm bin directory to environment variable for the binaries to be available from the command prompt.

    3. Starting nssm.exe with the following command:

      nssm.ext install service_name

    4. In the Path, providing the path to the batch file created in step 1.

    5. In the I/O section, providing the paths to stdin, stdout and stderr to check on the output.

    6. Click Install service.

    7. Start the service.