If you're trying to debug a web application locally you may have occasionally found that the port you've specified the app to run on is already in use by another service.
You may want to check which app is using the port, in case it's an error, or try to find a free port in order to switch your app's launch settings over to using a free one.
If you're using Windows, you can check a specific port's usage in PowerShell:
Get-Process -Id (Get-NetTCPConnection -LocalPort 5173).OwningProcess
Or if you prefer a GUI, you can open the Resource Monitor from the start menu and check the Network tab > Listening Ports (uou may need Administrator privileges to view this monitor).
You can switch the port an app runs on in a Visual Studio project by amending the launchSettings.json
Or if you're running an Express.js server, you can specify the port in your index.js, either hard-coded, or more commonly, by referencing an environment variable. The example below uses the environment variable PORT
, or 5000 if there's no value set.
const app = express()
const port = process.env.PORT || 5000
app.listen(port, () => console.log(`Server listening on port ${port}`))