Deploy node app with http-server and forever

前端 未结 5 1257
生来不讨喜
生来不讨喜 2021-02-06 12:01

I want to use http-server and forever.js to deploy my app to remote ubuntu server. But forever.js requires path to JS file, not to executable. So I can\'t pass keys to http-serv

5条回答
  •  我寻月下人不归
    2021-02-06 12:51

    I had the same issue. Found a node.js script that can run shell commands and used it to run the http-server command along with options.

    example of node.js script named 'startserver.js':

    var sys = require('sys')
    var exec = require('child_process').exec;
    function puts(error, stdout, stderr) { sys.puts(stdout) }
    exec("sudo http-server -a ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com -p 80", puts);
    

    Then you can run it using forever:

    forever start startserver.js
    

提交回复
热议问题