Created
December 14, 2010 17:56
-
-
Save psema4/740789 to your computer and use it in GitHub Desktop.
Simple Node.JS web server & client
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
// Modified from Node.JS documentation: http://nodejs.org/docs/v0.2.5/api.html#http-client-183 | |
var http = require('http'); | |
var server = http.createClient(8124, '127.0.0.1'); | |
var request = server.request('GET', '/', {'host': '127.0.0.1'}); | |
request.end(); | |
request.on('response', function (response) { | |
console.log('STATUS: ' + response.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(response.headers)); | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); |
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
// From Node.JS documentation: http://nodejs.org/ | |
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}).listen(8124, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:8124/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment