Deploying your application online
suggest changeA Node.js host usually sets a PORT environment variable. Listen on that value so the platform can route traffic to the process.
http in these snippets is require('http'). process.env.PORT is a string. listen accepts that string.
const http = require('http');
http.createServer(function(request, response) {
// your server code
}).listen(process.env.PORT);
To run the same file locally when PORT is unset:
const http = require('http');
http.createServer(function(request, response) {
// your server code
}).listen(process.env.PORT || 3000);
3000 is the local port used when PORT is not set.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents