Shortest functional Web Server Challenge (Any Language)

Made it 1 character smaller using koa (btw, I think it should be a rule that you can only use serious libraries, because otherwise it would be unfair)

new(require("koa"))().use(s=>s.body="Hello World!").listen()

EDIT: A shorter empty server using koa 1.6.2 (this is important):

require("koa")().listen()
2 Likes

yea, i think it should be one of those code jam rules where you have to use well-known libraries (well… depends on the def…), but cool usage!

Koa is meant to be express v4 (because updating express would mean a major rewrite), but yeah you decide if I can use it.

Also tried using net, which is a builtin like http:

require("net").Server(e=>e.end("HTTP/1.1 201\n\nHello World!")).listen()
2 Likes

I have a question: why http 201, not 200?

It’s shorter. With 200 you would need to write an extra OK as HTTP/1.1 200 OK\n\nHello World!

EDIT: saved some characters by using backticks in net

require("net").Server(e=>e.end(`HTTP/1.1 201

Hello World!`)).listen()
4 Likes