React and serve

During development of our React application, we’ll be using something like

yarn start

When we’re ready to deploy our application, we’ll use

yarn build

Which, in the case of React Typescript, will transpile to JavaScript and package files ready for deployment.

We can also serve the files within the build folder using the serve application.

Installing serve

To install serve, execute

yarn global add serve

This will add server to the global location. Normally (without the global command) packages etc. are installed local to the folder you’re working in. In the case of global packages, these will be installed in C:\Users\{username}\AppData\Roaming\npm\bin on Windows.

To check the location on your installation run

yarn global bin

Running serve on our build

Once serve is installed we can run it using

serve -s build

Note: Obviously if the global location is not in your path you’ll need to prefix the command with the previously found location