Deploy a node application with an http server and forever

I want to use http-server and forever.js to deploy my application to a remote ubuntu server. But forever.js requires a path to the JS file, not an executable. Therefore, I cannot transmit keys to the http server. The best solution so far is to install the http server locally through npm and run something like this: forever start ./node_modules/http-server/bin/http-server . But in this case, I can not set the port and other parameters. What is the best practice?

+5
source share
5 answers

You can set the parameters using this code. Just use the available flags after your team finishes. For instance:

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

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

example 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 forever:

 forever start startserver.js 
+9
source

It worked with me

First enter the path to the http server, like this

 which http-server 

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

then write forever, then follow the http-server path and your application path

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

Sincerely.

+4
source

Go to the directory containing your files And from the command line type: forever run -c http-server. -p your_port_number Example: forever start -c http-server -p 8000

Thus, port 8000 will forever point to html files in your directory.

0
source

Try the following:

forever start $(which http-server)

0
source

Source: https://habr.com/ru/post/1205055/


All Articles