process.env.PORT || 3000
app.set('port', process.env.PORT || 3000);
In many environments (e.g. Heroku), and as a convention, you can set the environment variable
PORT to tell your web server what port to listen on.
process.env.port || 3000 means: whatever is in the environment variable PORT, or 3000 if there's nothing there.
So you pass that
app.listen, or to
app.set('port', ...), and that makes your server be able to accept a parameter from the environment what port to listen on.
If you pass
3000 hard-coded to
app.listen(), you're always listening on port 3000, which might be just for you, or not, depending on your requirements and the requirements of the environment in which you're running your server.