Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

Hello World HTTP 서버

helloworld.js
var http = require('http');

http.createServer(function (request, response) {
	response.writeHead(200, {'Content-Type': 'text/plain'});
	response.end("Hello world\n")
}).listen(8000, '0.0.0.0');

console.log('Server started')

실행 및 테스트
# nodejs helloworld.js
# curl localhost:8000 

Echo 서버

var net=require('net')

net.createServer(function(socket) {
	socket.write("Echo Server....\n")
	socket.on('data', function(data) {
		socket.write(data.toString())
	})
}).listen(8000, 'localhost')

테스트
# nc localhost 8000
Echo Server....
Hello World
Hello World
Ok
Ok

Chat 서버