Using create-react-app with hapi.js

This short guide will easily show you how to use hapi.js with the popular create-react-app.

I often use hapi to proxy my API requests within React. There are countless Express guides showing you how to do this but I haven’t found one for hapi that screams simplicity.

First, you’ll need to install hapi itself and inert, a hapi plugin.

yarn add hapi inert

Next, create a server.js file and paste the following:

const Hapi = require('hapi')
const Path = require('path')

const server = new Hapi.Server()

const plugins = [

server.register(plugins, err => {
if (err) {
throw err

host: process.env.HOST || 'localhost',
port: process.env.PORT || 5000

method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: Path.join(__dirname, 'build'),
listing: false,
index: true

server.start(err => {
if (err) {
throw err

console.log(`Server running at ${}`)

Finally, when you deploy your server or run yarn run build you can then start your server by typing node server.

Enjoy 👋