Deploy node app with http-server and forever
Asked Answered
H

6

8

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?

Hogen answered 19/10, 2014 at 23:39 Comment(0)
R
16

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
Raddi answered 16/12, 2014 at 20:15 Comment(0)
G
10

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
Godding answered 6/11, 2014 at 15:44 Comment(0)
R
5

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

Repeat answered 6/11, 2017 at 7:45 Comment(3)
this actually is a clever answer.Cabrera
Hi I did this and it doesn't serve the html files on that path. doesn't open the ip in browser forever start $(which http-server) -p 8001 -a 10.4.145.192 falseGemagemara
How do i point to the script with your command above?Armidaarmiger
V
4

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.

Vallee answered 20/4, 2017 at 17:23 Comment(0)
S
1

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.

Sobriety answered 9/10, 2017 at 14:0 Comment(0)
W
0

This command works for me.

forever start npm\node_modules\http-server\bin\http-server

Before this you should find your npm directory.

Warfield answered 3/5, 2021 at 19:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.