Skip to content

Commit 69860f1

Browse files
authored
Merge pull request gothinkster#56 from deksden/fix-default-port
Use cross-env to change default port
2 parents 16e498f + b899d4a commit 69860f1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ To get the frontend running locally:
2121
- `npm install` to install all req'd dependencies
2222
- `npm start` to start the local server (this project uses create-react-app)
2323

24+
Local web server will use port 4100 instead of standard React's port 3000 to prevent conflicts with some backends like Node or Rails. You can configure port in scripts section of `package.json`: we use [cross-env](https://github.com/kentcdodds/cross-env) to set environment variable PORT for React scripts, this is Windows-compatible way of setting environment variables.
25+
26+
Alternatively, you can add `.env` file in the root folder of project to set environment variables (use PORT to change webserver's port). This file will be ignored by git, so it is suitable for API keys and other sensitive stuff. Refer to [dotenv](https://github.com/motdotla/dotenv) and [React](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-development-environment-variables-in-env) documentation for more details. Also, please remove setting variable via script section of `package.json` - `dotenv` never override variables if they are already set.
2427

2528
### Making requests to the backend API
2629

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6+
"cross-env": "^4.0.0",
67
"react-scripts": "0.8.5"
78
},
89
"dependencies": {
@@ -18,9 +19,9 @@
1819
"superagent-promise": "^1.1.0"
1920
},
2021
"scripts": {
21-
"start": "react-scripts start",
22+
"start": "cross-env PORT=4100 react-scripts start",
2223
"build": "react-scripts build",
23-
"test": "react-scripts test --env=jsdom",
24+
"test": "cross-env PORT=4100 react-scripts test --env=jsdom",
2425
"eject": "react-scripts eject"
2526
}
2627
}

0 commit comments

Comments
 (0)