Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Created May 1, 2019 20:10
Show Gist options
  • Select an option

  • Save bahamas10/a04013957f222df45d40a2fe4b00d45f to your computer and use it in GitHub Desktop.

Select an option

Save bahamas10/a04013957f222df45d40a2fe4b00d45f to your computer and use it in GitHub Desktop.
mike web server simple
var http = require('http');
var host = '0.0.0.0';
var port = 8080;
var server = http.createServer(onrequest);
server.listen(port, host, listening);
function listening() {
console.log('listening http://%s:%d', host, port);
}
function onrequest(req, res) {
switch (req.method) {
case 'GET':
res.end('you hit ' + req.url + '\n');
break;
case 'POST':
req.pipe(res);
break;
default:
res.statusCode = 405;
res.end('only GET and POST supported\n');
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment