0

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.

Borislav Stefanov
  • 533
  • 3
  • 15
  • 38
  • You can refer to https://stackoverflow.com/questions/3582108/create-windows-service-from-executable . – Prateek Sep 24 '21 at 08:24

1 Answers1

1

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.

Prateek
  • 333
  • 3
  • 10
  • Is this working for you? I mean I am not able to start the service this way. – Borislav Stefanov Sep 24 '21 at 12:07
  • can you give me more info on 2. Adding npm bin directory to environment variable for the binaries to be available from the command prompt. ? How to do it – Borislav Stefanov Sep 24 '21 at 12:12
  • 'http-server' is not recognized as an internal or external command, operable program or batch file - this is what stderr is saying – Borislav Stefanov Sep 24 '21 at 12:16
  • Actually this solved the step 2 Make sure the locations of both npm and http-server are added in environment variable 'PATH' (Both user variable and System variable). If it is not present, add C:\Users\username\AppData\Roaming\npm and C:\Users\username\AppData\Roaming\npm\node_modules\http-server to environment variable 'PATH' – Borislav Stefanov Sep 24 '21 at 12:19
  • For 2, follow the answers on https://stackoverflow.com/questions/9546324/adding-a-directory-to-the-path-environment-variable-in-windows – Prateek Sep 24 '21 at 12:19
  • I added C:\Users\username\AppData\Roaming\npm to path variable and it worked for me – Prateek Sep 24 '21 at 12:20
  • I agree. This is the working answer. Thank you – Borislav Stefanov Sep 24 '21 at 12:30