Skip to content

Instantly share code, notes, and snippets.

@Waltari10
Created November 9, 2019 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Waltari10/5dbfd3c87064df5a5fdbbc15e2cc1db8 to your computer and use it in GitHub Desktop.
Save Waltari10/5dbfd3c87064df5a5fdbbc15e2cc1db8 to your computer and use it in GitHub Desktop.
// Comes with Node
const http = require('http');
// Access dynamic Heroku port with process.env.PORT. 3001 is a fallback.
const port = process.env.PORT || 3001;
// Create a server
const server = http.createServer((req, res) => {
// If call was made to /hello-world pathname. We aren't using REST here!
if (req.url === '/hello-world') {
res.end('hello world!');
return;
}
// Make sure to terminate other requests too, so they don't hang indefinedly.
res.end('');
});
// Actually start the server
server.listen(port);
console.log('Running on port: ' + port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment