Go Ruby Node.js

Go

1
2
3
4
5
6
7
8
9
10
11
package main

import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
})
http.ListenAndServe(":8000", nil)
}

Ruby

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'socket'

server = TCPServer.open 9000
puts "Listening on port 9000"

loop {
client = server.accept()
while((x = client.gets) != "\r\n")
puts x
end
resp = "Hello World!"
headers = ["HTTP/1.1 200 OK",
"Date: Tue, 14 Dec 2010 10:48:45 GMT",
"Server: Ruby",
"Content-Type: text/html; charset=iso-8859-1",
"Content-Length: #{resp.length}\r\n\r\n"].join("\r\n")
client.puts headers
client.puts resp
client.close
puts "Request Handled"
}

Nodej.s

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World!');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
})