create-react-app: how to use https instead of http?

In Case of MAC/UNIX do

export HTTPS=true
npm start

Or simple one liner

export HTTPS=true&&npm start

Or update start script in package.json to

"start": "export HTTPS=true&&PORT=3000 react-scripts start",

you should be able to hit https.


You can edit your package.json scripts section to read:

"scripts": { "start": "set HTTPS=true&&react-scripts start", ... }

or just run set HTTPS=true&&npm start

Just a sidenote, for me, making this change breaks hot reloading for some reason....

-- Note: OS === Windows 10 64-Bit


You can also create a file called .env in the root of your project, then write

HTTPS=true

After that, just run "npm start" as you usually do to start your app.

Docs: https://facebook.github.io/create-react-app/docs/advanced-configuration

Works both on Linux and Windows, unlike some other answers posted here.


Set HTTPS=true before you run the start command.

Documentation

The implementation uses the HTTPS Environment Variable to determine which protocol to use when starting the server.