My project is based on create-react-app. npm start
or yarn start
by default will run the application on port 3000 and there is no option of specifying a port in the package.json.
How can I specify a port of my choice in this case? I want to run two of this project simultaneously (for testing), one in port 3005
and other is 3006
Here is another way to accomplish this task.
Create a .env file at your project root and specify port number there. Like:
PORT=3005
Just update a bit in
webpack.config.js
:then run
npm start
againYou can specify a environment variable named
PORT
to specify the port on which the server will run.You could use cross-env to set the port, and it will work on Windows, Linux and Mac.
then in package.json the start link could be like this:
Changing in my package.json file
"start": "export PORT=3001 && react-scripts start"
worked for me too and I'm on macOS 10.13.4