Why use process.env.PORT instead of hardcoding?
Production environments (AWS, Heroku, Render) set their own port. Hardcoding 3000 means your server cannot bind there. Always use process.env.PORT || 3000 so it works in dev and prod.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Express Port Binding and Listen Explained
It tells Node's HTTP module to listen on a port. Express calls http.createServer(app) under the hood. When a request arrives on that port, Express's middleware chain runs and dispatches to the handler.
If app.js only creates the app (no listen), you can import it in tests without binding to a port. server.js is the only file that calls listen. This pattern is small but useful for testing.
Address already in use. Something is already running on that port. Either another server is up or your old process did not quit. Kill it or use a different port.
Still have questions?
Browse all our FAQs or reach out to our support team
