Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to specify port when running the server? #1083

Closed
ghost opened this issue Nov 22, 2016 · 15 comments

Comments

@ghost
Copy link

commented Nov 22, 2016

My project is based on create-react-app. npm 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

SO Question

@riceyeh

This comment has been minimized.

Copy link

commented Nov 22, 2016

You can specify your port with process.env.PORT. It can be done by changing the script for start in package.json as shown below:

"start": "PORT=3006 react-scripts start"

@ghost

This comment has been minimized.

Copy link
Author

commented Nov 22, 2016

You mean my package.json will be

{
  "start": "PORT=3006 react-scripts start",
  "name": "igene-web",
  "version": "0.1.0"......... }

then npm start?

didn't work for me (windows and ubuntu)

@dvkndn

This comment has been minimized.

Copy link
Contributor

commented Nov 22, 2016

@fireflieslive no it is not. You should change the start command inside scripts section in your package.json

@ghost

This comment has been minimized.

Copy link
Author

commented Nov 22, 2016

haha, where am i looking. thanks!

@dvkndn

This comment has been minimized.

Copy link
Contributor

commented Nov 22, 2016

You're welcome. If your issue is solved you can close the issue :D

@ghost ghost closed this Nov 22, 2016

@ghost

This comment has been minimized.

Copy link
Author

commented Nov 22, 2016

works with ubuntu, not with windows:


'PORT' is not recognized as an internal or external command,
operable program or batch file.
@dvkndn

This comment has been minimized.

Copy link
Contributor

commented Nov 22, 2016

The above command is Unix (Ubuntu, Mac, etc…). In windows enviroment, you need a different syntax. Google something like "set env in windows command line"

@Delapouite

This comment has been minimized.

Copy link

commented Nov 22, 2016

For windows you can use cross-env https://www.npmjs.com/package/cross-env

@gaearon

This comment has been minimized.

Copy link
Member

commented Nov 22, 2016

You can also create an .env file with

PORT=3006

and save it in your project directory.

@rugglcon

This comment has been minimized.

Copy link

commented Dec 11, 2016

This worked for me on elementaryOS, thanks!

@philipjmurphy

This comment has been minimized.

Copy link

commented Jul 29, 2017

On Windows with yarn this worked for me:

"scripts": {
    "start": "set PORT=3006 && react-scripts start",
    ....
@ulrikwalter

This comment has been minimized.

Copy link

commented Sep 27, 2017

Or use npm cross-env (without &&!)

"scripts": {
    "start": "cross-env PORT=3006 react-scripts start",
}
@webmobiles

This comment has been minimized.

Copy link

commented Nov 12, 2017

how to do it with the build folder ?

@Timer

This comment has been minimized.

Copy link
Collaborator

commented Nov 12, 2017

Deployment is a bit different, you can read our documentation on that @webmobiles.
Open an issue if you run into any trouble / find something wrong!

@Yonben Yonben referenced this issue Nov 28, 2017
@aleczratiu

This comment has been minimized.

Copy link

commented Dec 12, 2017

"start": "PORT=3006 react-scripts start"
in package.json change it.

@facebook facebook locked and limited conversation to collaborators Dec 12, 2017

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
10 participants
You can’t perform that action at this time.