ng serve 명령을 실행할 때“포트 4200이 이미 사용 중입니다”
나는 각도 2를 배우고 있으며 처음으로 각도 CLI 프로젝트를 사용하여 샌드 박스 프로젝트를 만들고 있습니다.
"ng serve"명령을 실행할 수 있었고 훌륭하게 작동합니다. "Control Z"를 실행하도록 실행을 중지하고 싶었습니다.
"ng-serve"명령을 다시 실행하려고하면 "포트 4200이 이미 사용 중입니다"라는 메시지가 표시됩니다.
PID 목록을 얻기 위해 "PS"를 실행하고 angular-cli의 PID를 종료하고 "ng-serve"를 다시 실행했지만 여전히 동일한 포트 사용 오류가 발생합니다.
이것은 포트 4200에서 진행 상황을 죽이는 데 사용한 것입니다.
Linux 사용자의 경우 :
sudo kill $(sudo lsof -t -i:4200)
당신은 또한 이것을 시도 할 수 있습니다 :
sudo kill `sudo lsof -t -i:4200`
Windows 사용자의 경우 :
포트 번호 4200이 이미 사용 중입니다. 관리자 권한으로 cmd를 엽니 다. cmd에 아래 명령을 입력하십시오.
netstat -a -n -o
그런 다음 터미널을 마우스 오른쪽 버튼으로 클릭하여 포트 번호가 4200 인 포트를 찾은 다음 찾기를 클릭하고 "찾을 내용"에 4200을 입력하고 "다음 찾기"를 클릭하십시오. 포트 번호 4200이 pid 18932에 의해 사용되었다고 가정하십시오. 아래 명령을 입력하십시오. cmd :
taskkill -f /pid 18932
당신을 열고 cmd.exe
으로 administrator
,
그런 다음 PID
의port 4200
netstat -ano | findstr :4200
여기에 3 PID가 있습니다 :
- 빨간색은 "ng-serve"(127.0.0.1:4200)에서 나온 것입니다.
LISTENING
- 녹색은 "브라우저"에서 나온 것입니다.
포트 4200 만 종료 (빨간색 PID 종료) :
taskkill /PID 15940 /F
참고 : 녹색을 죽이면 브라우저가 강제로 닫힙니다.
이제 "ng-serve"를 수행하여 동일한 포트 4200에서 각도 앱을 시작할 수 있습니다
추가 사항 :
하나의 라이너 : 이것을 최적화하는 방법을 찾은 후 여기 에이 대답의 하나의 라이너 명령이 있습니다 : ( 이 팁에 대한 Josep Alsina의 특별한 감사 )
for /f "tokens=5" %a in ('netstat -ano ^| find "4200" ^| find "LISTENING"') do taskkill /f /pid %a
Mac OS X에서는 다음 명령이 필요합니다.
sudo lsof -t -i tcp:4200 | xargs kill -9
Command + C를 사용하여 Angular의 웹 서버를 종료해야합니다.
ctrl + Z가 아니라 ctrl + C 중지를 위해 실행해야합니다.
ng를 종료하려면이 명령을 사용하십시오.
pkill -9 ng
ng serve --port <YOUR_GIVEN_PORT_NUMBER>
주어진 포트에서 실행하려면 위의 명령을 시도해야합니다.
을 사용 Ctrl+Z
하면 실행중인 작업을 일시 중단하지만 종료하지는 않습니다. 나중에 명령 fg
을 사용 하여 작업을 다시 시작할 수 있습니다 . 종료 ng serve
하려면 Ctrl+C
대신 4200 포트를 해제해야합니다.
다음 명령으로 포트를 강제 종료 할 수 있습니다.
kill -2 $(lsof -t -i:4200)
Windows의 경우 :
열기 명령 프롬프트 및
유형: netstat -a -o -n
종료하려는 프로세스의 PID를 찾으십시오.
유형: taskkill /F /PID 16876
이 하나의 16876은 죽이고 싶은 프로세스의 PID입니다.이 경우 프로세스는 4200입니다-첨부 파일을 확인하십시오. 모든 포트 번호를 제공 할 수 있습니다.
Now, Type : ng serve
to start your angular app at the same port 4200
Right now you can set --port 0
to get a free port.
ng serve --port 0 // will get a free port for you
netstat -anp | grep ":4200"
This will tell you who's got the port.
I am sharing this as the fowling two commands did not do the job on my mac:
sudo kill $(sudo lsof -t -i:4200)
sudo kill `sudo lsof -t -i:4200`
The following one did, but if you were using the integrated terminal in Visual Code, try to use your machine terminal and add the fowling command:
lsof -t -i tcp:4200 | xargs kill -9
I also faced the same error msg, so i tried ng serve --port 12012 and it worked fine.
ng serve --port 4201 --live-reload-port 4200
and access using localhost:4201
This should work as a temporary solution.
or
try listing port usage using
lsof -i:4200
and kill it manually using
sudo kill -9 <Process PID using port 4200>
Just restart the IDE you are using, then it will work.
In summary there are more than one solution : 1 ) By using another port to define port number ,
ng serve --open --port 4201
2) by killing the process
ctrl + c // for kill
Close all node terminal which is related for running the app.
3) Type
netstat -a -n -o
in command prompt then find the related port PID and kill it by
taskkill /F /PID (pid number)
4) Type netstat -ano|findstr :4200
took the foreign address PID which contain the port number and then kill it by
taskkill /PID (pid number)/F
With ctrl + z you put the program in the background. On Linux you can get the session back in the foreground with the following command:
fg ng serve
You don't need to kill the process.
You can also try with this to run your application in visual studio code -:
ng serve --open --port 4201
you can give any port number.
The most simple one line command:
sudo fuser -k 4200/tcp
To stop all the local port running in windows, use this simple comment alone instead searching for pid separatly using netstat,
It find all the pid and stop the local port which is currently running,
taskkill /im node.exe /f
If you are using VSCode, you have the option to kill terminal and add a new terminal. Close the tab and open a new tab. It worked for me.
Edited: Use ctrl+c and press y. With out killing terminal also, You can proceed. If you want to open a new instance of visual studio and run a different application , you can use ng serve --port 4401.
you can use fuser -k 4200/tcp if it is Linux Operating system
Kill process and close the terminal which you used for running the app on that port.
Instead of killing the whole process or using ctrl+z
, you can simply use ctrl+c
to stop the server and can happily use ng serve command
without any errors
or if you want to run on a different port simply use this command ng serve --port portno(ex: ng serve --port 4201)
.
For Ubndu 18.04 sudo lsof -t -i tcp:3000 | xargs kill -9
Its happen when port was unsucessfully terminated so this command will terminat it 4200 or 3000 or3300 any
If you compiling your angular JS code in both CMD and IDE then this issue occur. In CMD, your angular JS code compile automatically whenever you change your angular JS code in IDE and then your IDE want to occupy the same port i.e 4200 which is occupied by CMD already So, there is a simple solution for this issue, just close your cmd while compiling your code in IDE.
I was facing the same issue every time I have to kill the port.
I tried ./node_modules/.bin/ng serve --proxy-config proxy.conf.json --host 0.0.0.0
Instead of npm start
and its works
On linux mint 17, this is working.
kill -9 $(lsof -t -i:4200)
It is possible to change port in .angular-cli
file. For example:
"defaults": {
"styleExt": "css",
"component": {},
"serve": {
"port": 4205
}
}
In addition, it is necessary to add this to your package.json
:
"ng": "ng",
"start": "ng serve"
It says already we are running the services with port no 4200 please use another port instead of 4200. Below command is to solve the problem
ng serve --port 4300
'programing tip' 카테고리의 다른 글
'new'를 사용하면 왜 메모리 누수가 발생합니까? (0) | 2020.06.30 |
---|---|
왜 누군가가 unorder_set 대신 set을 사용합니까? (0) | 2020.06.30 |
안드로이드 clipToPadding 속성은 무엇을합니까? (0) | 2020.06.30 |
문자열에서 줄 바꿈 (문자 없음)을 제거하는 방법은 무엇입니까? (0) | 2020.06.30 |
NSManagedObject의 특정 하위 클래스를 찾을 수 없습니다 (0) | 2020.06.29 |