Deploy node app with http-server and forever

僤鯓⒐⒋嵵緔 提交于 2019-12-04 12:24:50

问题


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-server. Best solution so far is to install http-server locally via npm and run something like this: forever start ./node_modules/http-server/bin/http-server. But in this case I can't set port and other options. What's the best practice?


回答1:


You can set the options using that code. Just use the available flags after the end of your command. For example:

forever start ./node_modules/http-server/bin/http-server -p 80 -d false



回答2:


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



回答3:


This worked with me

First get path of http-server like this

which http-server

for example you will get "/usr/bin/http-server"

then after that write the forever followed by http-server path and your app path

forever start /usr/bin/http-server /your/app/path

Best regards.




回答4:


Try this:

$ forever start $(which http-server) -p 8000 -d false

you can add any parameters after forever start $(which http-server)

$(which http-server): return the http-server path
-p 8000 : port 8000, change it to any port number
-d: Show directory listings




回答5:


Browse to your directory that contains your files And from the command line type: forever start -c http-server . -p your_port_number Example: forever start -c http-server -p 8000

In this way, the port 8000 will forever point to the html files in your directory.



来源:https://stackoverflow.com/questions/26456618/deploy-node-app-with-http-server-and-forever

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!