Created
October 5, 2018 17:51
-
-
Save lucianmachado/f00ea28250ac5afa3ffede692b367a34 to your computer and use it in GitHub Desktop.
Socket Nodejs HTTP Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
const OUTPUT = "<html><head><title>Example</title></head><body><p>Worked!!!</p></body></html>"; | |
const OUTPUT_HEADERS = "HTTP/1.1 200 OK\r\n" + | |
"Content-Type: text/html\r\n" + | |
"Content-Length: "; | |
const OUTPUT_END_OF_HEADERS = "\r\n\r\n"; | |
var server = net.createServer(function(socket) { | |
socket.write(OUTPUT_HEADERS + OUTPUT.length + OUTPUT_END_OF_HEADERS + OUTPUT); | |
}); | |
server.listen(1337, '127.0.0.1'); | |
console.log("Running server on 1337") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment