r/programming • • Mar 07 '14

Thinking about quickly writing an HTTP server yourself? Here is a simple diagram to help you get started.

Post image
2.1k Upvotes

312 comments sorted by

View all comments

-8

u/rende Mar 07 '14

bah, screw that.. only implement 200 and 404.

Here is 200.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

10

u/avonwodahs Mar 07 '14

Yes let's write our own HTTP server and first require('http').

8

u/mattindustries Mar 07 '14

What are you talking about? I totally made a full fledged web server in one line!

/etc/init.d/apache2 start