1

I'm trying to use http-server with forever but keep running into problems. Running

http-server -p 30004 ./dist

works correctly, however when I try to run

forever start --uid "host-manager-app-30004" -l C:\Users\cross.kalp\khm\host-manager-app.log --append -c "http-server -p 30004" ./dist

the application does not start. Forever shows this in the terminal:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: ./dist

but forever list shows no processes running and this appears in the log:

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: spawn http ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn http',
  path: 'http',
  spawnargs: [ 'C:\\Users\\cross.kalp\\khm\\dist' ]
}

I'm not quite sure what I'm doing wrong, any help would be appreciated.

I also tried to use pm2 instead, formatting my command according to Running NodeJs http-server forever with PM2, however I ran into errors using this method as well. Using the command

pm2 start C:/Users/cross.kalp/AppData/Roaming/npm/http-server --log C:\Users\cross.kalp\khm\host-manager-app.log  --name host-manager-app-30004 -- -p 30004 

led to this error in the log:

C:\Users\cross.kalp\AppData\Roaming\npm\http-server:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Object.<anonymous> (C:\Users\cross.kalp\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
C:\Users\cross.kalp\AppData\Roaming\npm\http-server:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

Any pointers for either of these methods would be greatly appreciated, thank you.

ckalp67
  • 11
  • 2
  • 1
    The second error is clear, there are messy quotes: `dirname "$(echo "$0"` ; after `echo` there is a closing quotation mark , so the `)` appears to be missing – pierpy Jun 01 '23 at 17:01
  • @pierpy odd, that's in the http-server source code, so you wouldn't think that'd be an issue. I tried escaping and also completely deleting the quotes around $0, just to see, and the exact same error was thrown regardless – ckalp67 Jun 01 '23 at 18:14

0 Answers0