Hi I want to use serve for production however when ever I run it using
serve -s build
it is killed whenever I close the terminal or press ctrl-c.
I'm pretty sure that there are better ways than this but you can run it as a background process (see here information: https://kb.iu.edu/d/afnz):
serve -s build &
You also might want to redirect stdout & stderr into a separate file for logging.
@sarfrazarshad You can use something like screen or tmux to keep the session open. Also, take a look at pm2, you can do a lot of things with it.
鈽濓笍 Exactly.
Or create a Node.js child process to fork it into the background. But this is definitely not something that serve needs to support - i hope you understand.
@pablopunk do you know how I could run "serve . --single -p 4000" but with pm2?
@burtontanner what's the problem with that?
@pablopunk I was wanting to do something like "pm2 start 'serve --single -p 4000'". I ended up creating a bash script (serve.sh) that contained 'serve . --single -p 4000'. Then I could run 'pm2 start serve.sh'.
@pablopunk I was trying to run something like 'pm2 start "serve . --single -p 4000"'. I ended up creating a bash script (serve.sh), and putting 'serve . --single -p 4000' inside it. Then I ran pm2 with 'pm2 start serve.sh'
@burtontanner That looks like it should be an npm start script:
// package.json
{
"scripts": {
"start": "serve . --single -p 4000"
}
}
And then you can use pm2 to run npm scripts:
pm2 start npm -- start
Ahh I didn't think of that. Thanks @pablopunk
Most helpful comment
@burtontanner That looks like it should be an
npm startscript:And then you can use pm2 to run npm scripts: