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.
So process.env.PORT || 3000
means: whatever is in the environment variable PORT, or 3000 if there’s nothing there.
So you pass that to app.listen
, or to app.set('port', ...)
, and that makes your server able to accept a “what port to listen on” parameter from the environment.
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.
Related Posts:
- Significance of port 3000 in Express apps
- stop all instances of node.js server
- Start script missing error when running npm start
- Node.exe Stuck at 100% CPU
- How do I debug error ECONNRESET in Node.js?
- How do I debug error ECONNRESET in Node.js?
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- What is Express.js?
- Cannot GET / Nodejs Error
- What is NODE_ENV and how to use it in Express?
- What does body-parser do with express?
- node.js, Error: Cannot find module ‘express’
- TypeError: Router.use() requires middleware function but got a Object
- node.js, Error: Cannot find module ‘express’
- nodemon – app crashed – waiting for file changes before starting
- “Topology was destroyed” when using MongoDB with native driver and Express.js
- What does “res.render” do, and what does the html file look like?
- Error: getaddrinfo ENOTFOUND in nodejs for get call
- nodemon not working: -bash: nodemon: command not found
- Failed to load resource: net::ERR_CONNECTION_REFUSED : Nodejs
- SyntaxError: Unexpected token import – Express
- Error: No default engine was specified and no extension was provided
- ExpressJS – throw er Unhandled error event
- NodeJS / Express: what is “app.use”?
- Why am I getting “Error socket hang up” response?
- Node.js Port 3000 already in use but it actually isn’t?
- How to Create and Use Enum in Mongoose
- First Heroku deploy failed `error code=H10`
- How to get GET (query string) variables in Express.js on Node.js?
- Express Render not working return error: No default engine was specified and no extension was provided
- TypeError: Router.use() requires middleware function but got a Object
- Error: Cannot find module ‘ejs’
- First Heroku deploy failed `error code=H10`
- In express how do I redirect a user to an external url?
- ExpressJS – throw er Unhandled error event
- ENOENT, no such file or directory
- ExpressJS : res.redirect() not working as expected?
- Push items into mongo array via mongoose
- Express error – TypeError: Router.use() requires middleware function but got a Object
- Expressjs / Node.js – res.redirect() not loading page
- MissingSchemaError: Schema hasn’t been registered for model “User”
- NodeJS w/Express Error: Cannot GET /
- Express.js req.body undefined
- Enabling HTTPS on express.js
- Make Axios send cookies in its requests automatically
- How do I remove documents using Node.js Mongoose?
- What is index.js used for in node.js projects?
- How to update a record using sequelize for node?
- heroku is giving me Method not allowed
- passport.js passport.initialize() middleware not in use
- Error: Cannot find module html
- ExpressJS vs MeteorJS
- How to access the request body when POSTing using Node.js and Express?
- TypeError: res.status is not a function
- TypeError: res.json is not a function
- SyntaxError: expected expression, got ‘<'
- How can I use webpack with express?
- Cannot POST / error using express
- Route.get() requires callback functions but got a “object Undefined”
- nodemon not working properly
- Passport.js – Error: failed to serialize user into session
- npm WARN package.json: No repository field
- Advice on loopback.js vs express js
- How to update a array value in Mongoose
- How do I use HTML as the view engine in Express?
- Hapi/Joi Validation: How to process text to a specific format
- bodyParser is deprecated express 4
- Why is Node.js scalable?
- Cannot access mongodb through browser – It looks like you are trying to access MongoDB over HTTP on the native driver port
- [npm notice created a lockfile as package-lock.json. You should commit this file
- What port should I open to allow remote desktop?
- What ports to open for mail server?
- What firewall ports need to be open to allow access to external git repositories?
- How do high traffic sites service more than 65535 TCP connections?
- What is this JavaScript “require”?
- Difference between binary semaphore and mutex
- Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
- how to use CryptoJS in javascript
- Hidden field “ufprt” being added to Razor Umbraco Form – Why?
- What is the difference between a port and a socket?
- XMLHttpRequest module not defined/found
- git add only modified changes and ignore untracked files
- HTTP Error 404.3-Not Found in IIS 7.5
- What is the difference between procedural programming and functional programming?
- Properly close mongoose’s connection once you’re done
- NPM install fails with node-gyp
- How to properly upgrade node using nvm
- How to get the vector between two vectors?
- Brackets.io in built support for TypeScript
- 10 servers to administer and I’m a history major [closed]
- Making `wget` not save the page
- How do I list all connected Salt Stack minions?
- How to get Apache2 to redirect to a subdirectory
- What does that mean: packages excluded due to repository priority protections
- How can I set a short timeout with the ping command?