React&React-Native/React
[#. React] React 기본 실행 3000 port 변경하기
shab
2021. 7. 8. 10:31
반응형
React는
npm run start
명령어로 실행하게 되면 기본적으로 3000 port에서 실행된다
이 3000 port를 다른 port로 바꿔보자
① 명령어로 실행하기
PORT=3002 npm run start
이렇게 실행하면 일회성으로만 적용된다
② package.json 수정하기
⑴ Mac, Linux
...
"scripts": {
"start": "export PORT=3002 && react-scripts start",
}
...
⑵ Window
...
"scripts": {
"start": "set PORT=3002 && react-scripts start",
}
...
③ 프로젝트명/node_modules/react-scripts/scripts/start.js 수정하기
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3002; // 수정
const HOST = process.env.HOST || '0.0.0.0';
④ .env 파일 생성하고 port 설정하기
프로젝트명/.env
PORT=3002
명령어로 실행
npm run start
반응형