Created
August 14, 2019 20:29
-
-
Save cfernandomaciel/9f1ed13d4555ea51d3a6203e36f8c5bd to your computer and use it in GitHub Desktop.
Simple Server with port 15000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const portscanner = require('portscanner'); | |
//const port = process.env.PORT; | |
const requestHandler = (request, response) => { | |
console.log(request.url) | |
response.end('Hello Node.js Server!') | |
} | |
const server = http.createServer(requestHandler) | |
portscanner.findAPortNotInUse(15000, 16000, 'localhost', (error, port) => { | |
server.listen(port, (err) => { | |
if (err) { | |
return console.log('something bad happened', err) | |
} | |
console.log(`server is listening on ${port}`) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment