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

I was wondering if anyone knows how to use https on dev for the 'create-react-app' environment. I can't see anything about that in the README or quick googling. I just want either the https://localhost:3000 to work, or else https://localhost:3001.


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.


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.


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.