Skip to content

Instantly share code, notes, and snippets.

@antics
Created January 6, 2012 19:49
Show Gist options
  • Save antics/1572081 to your computer and use it in GitHub Desktop.
Save antics/1572081 to your computer and use it in GitHub Desktop.
Stofor 01
// importera http-modulen
var http = require('http');
//
// Skapar en webbserver och spottar ut två variabler (objekt),
// request och response, som innehåller en massa rolig information och
// användbara metoder.
//
// request: http://nodejs.org/docs/latest/api/http.html#http.ServerRequest
// response: http://nodejs.org/docs/latest/api/http.html#http.ServerResponse
//
http.createServer(function (request, response) {
// variabel (objekt) med nyckeln Content-Type
// och värdet text/plain
var documentSettings = {
'Content-Type': 'text/plain'
};
// Metoden (writeHead) i response-objektet som säger åt webbläsaren
// vad det är för typ av "dokument" den ska visa.
response.writeHead(200, documentSettings);
// write skickar grejjer till webbläsaren.
response.write('Hej Stoffe');
// Inget mer kan skickas efter end.
response.end();
}).listen(8080, "127.0.0.1");
// Skriver ut meddelande i terminalen.
console.log('Server running at http://127.0.0.1:8080/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment