Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serve -s build specify port number

I'm trying to serve a react-app's build folder from a DigitalOcean droplet.

After I run yarn build, I get told by the script to run

yarn global add serve serve -s build

However, when I run serve -s build, It say's it's running on http://localhost:5000. I would like it run on localhost:3000 instead, as I have another server running on port 5000. How can i specify the port number such that serve -s build runs on port 3000?

like image 568
rma Avatar asked Oct 07 '18 20:10

rma


People also ask

What port should I use for production?

Any port 1024 or higher outside that list should be safe, but if users are trying to access your site from a hostile environment you'll have to experimentally find out which ports are unfiltered. You really want to use port 80/443 for best interoperability.

How do I change my Nextjs port?

Change port with nextjs script json file in the script section. Make sure to change the port with -p flag in nextjs scripts. "scripts": { "dev": "next -p 3002", "build": "next build", "start": "next start -p 3002",}, You also change the port for different environments like dev, build and start in nextjs.


1 Answers

From typing serve --help, I found

-l, --listen listen_uri            
Specify a URI endpoint on which to listen

For TCP ports on hostname "localhost":

$ serve -l 1234

In your case, you can just use

serve -l 3000 -s build

to specify that you want to serve the app on port 3000

like image 115
Hiccup Avatar answered Sep 19 '22 03:09

Hiccup