Jonatan Tibarovsky
Jonatan Tibarovsky

Reputation: 93

How to change PORT number and run serve forever?

I'm building an app with create-react-app and I'm serving the production version via serve. I would like to run it on port 80 and run it forever even after I log out of the terminal.

Upvotes: 0

Views: 1791

Answers (2)

Mufasil Faizal
Mufasil Faizal

Reputation: 23

Build application first,

sudo npm run build

Then,

sudo serve -s build -p 80

Upvotes: 1

Richard Petrosino
Richard Petrosino

Reputation: 23

Look into learning a backend server framework like Express if you are interested in deploying your own production applications.

With Express, you can point specific URL requests to specific static files and apply any data retrieval / setting in the process.

There are also a number of specific resources available for transitioning create-react-apps to Express backends.

When you make this jump, if you haven't already, the important thing to remember is that you are essentially coding two applications, one is the frontend application that user sees, which is rendered in their browser by the bundled React code, and the other application is the backend server which routes and organizes those static javascript files for delivery to the users browser. When they connect to your server, they are sent to Express, which in turn (depending on the request) sends the React javascript.

Upvotes: 1

Related Questions