Skip to content

Instantly share code, notes, and snippets.

@Waltari10 Waltari10/server.js
Created Nov 9, 2019

Embed
What would you like to do?
// 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
You can’t perform that action at this time.