Port is occupied, how to cancel?

  node.js, question

When starting a NODE application under MAC, an error is reported

Port 8021 is already in use

But use

lsof -i tcp:8021

But there is no reality

Restart countless times, or the same, exactly is what ghost?

I finally found the user of the port, but how to clear it seems that the authority is not enough.

sudo lsof -n -P|grep :8021
 launchd     1            root    7u     IPv6 0xd801a7a2b2bdf8f5        0t0     TCP [::1]:8021 (LISTEN)
 launchd     1            root   15u     IPv4 0xd801a7a2b2be5e15        0t0     TCP (LISTEN)
 launchd     1            root   16u     IPv6 0xd801a7a2b2bdf8f5        0t0     TCP [::1]:8021 (LISTEN)
 launchd     1            root   17u     IPv4 0xd801a7a2b2be5e15        0t0     TCP (LISTEN)

Later, I turned to stackoverflow. Some people encountered similar problems with me. The port was occupied by launchd process, but I didn’t know what program was in use and could kill the process.

Someone suggested looking for the relevant. plist

find ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons -name "*.plist" -exec grep -H 8021 "{}" \;  2>/dev/null


/System/Library/LaunchDaemons/com.apple.airportd.plist:                <string>IO80211Controller</string>
 /System/Library/LaunchDaemons/com.apple.eapolcfg_auth.plist:    <string>/System/Library/PrivateFrameworks/EAP8021X.framework/Resources/eapolcfg_auth</string>
 /System/Library/LaunchDaemons/com.apple.ftp-proxy.plist:            <string>8021</string>

Found the problem, it turned out that the company’s wireless network was not good recently, so I turned on AIRPORT. So I tried to turn off sharing, and port 8021 was released after restarting.

It can be seen that port 8021 is occupied by the system by default, so it is better to bypass it when customizing.