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
Closed

Option to specify port when running the server? #1083

ghost opened this issue Nov 22, 2016 · 15 comments

Comments

@ghost
Copy link

ghost 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
Copy link

riceyeh 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
Copy link
Author

ghost 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)

@thien-do
Copy link
Contributor

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

@ghost
Copy link
Author

ghost commented Nov 22, 2016

haha, where am i looking. thanks!

@thien-do
Copy link
Contributor

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

@ghost ghost closed this as completed Nov 22, 2016
@ghost
Copy link
Author

ghost 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.

@thien-do
Copy link
Contributor

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
Copy link

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

@gaearon
Copy link
Contributor

gaearon commented Nov 22, 2016

You can also create an .env file with

PORT=3006

and save it in your project directory.

@rugglcon
Copy link

rugglcon commented Dec 11, 2016

This worked for me on elementaryOS, thanks!

@pjm4
Copy link

pjm4 commented Jul 29, 2017

On Windows with yarn this worked for me:

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

@ulrikwalter
Copy link

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

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

@webmobiles
Copy link

how to do it with the build folder ?

@Timer
Copy link
Contributor

Timer 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!

@aleczratiu
Copy link

"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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants