Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Created February 11, 2022 22:43
Show Gist options
  • Save karl-gustav/61a2332ad19da596032bfbcb6222f4a4 to your computer and use it in GitHub Desktop.
Save karl-gustav/61a2332ad19da596032bfbcb6222f4a4 to your computer and use it in GitHub Desktop.
Minimal pure node js server
const http = require('http');
const url = require('url');
function handler(req, res) {
res.writeHead(200, {'Content-type':'text/plain'});
res.write('Hello, I am a webserver !');
res.end();
}
const port = process.env.PORT || 8080;
console.log('Server listening on http://localhost:'+port);
const server = http.createServer(handler);
server.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment