How to run reactjs (using create-react-app) on a server

1.4k views Asked by At

So I obviously can't access localhost:3000 on my server, so I wanted to test it via the ip address with subfolders e.g. (192.0.1.168/reactjs). I've run npm run build and I've gone into the build folder, but it displays an empty page.

Am I missing something?

2

There are 2 answers

4
AudioBubble On

npm run build compiles your source files into a minified version of your app. This version can be found inside your /build directory.

If you want to serve this compiled version, you need to setup a webserver. Most common around are "Apache" and "nginx". Configure your webserver to use your /build directory as the root directory.

For configuration advices of your webserver you should read the documentation of the choosen one.

0
A. L On

Solved it by adding "homepage": "/reactjs/build", to package.json. Didn't work before as I didn't put build in it as well.

So the next question is, how do I change the build location, so that I can access it via www.website.com/reactjs rather than www.website.com/reactjs/build.