Page 155 - Nodejs 교과서 개정2판
P. 155
§ Ӓܿ ࢲߡ प೯ ചݶ IUUQ MPDBMIPTU
ࢲߡܳ ઙܐೞ۰ݶ ࣛীࢲ $USM $ ܳ ੑ۱ೞݶ ؾפ ࢿҕਵ۽ ࢲߡܳ प೯೮ਵפ द ٘ ղਊ
ਸ ಝࠇद
server1.js
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.write('<h1>Hello Node!</h1>');
res.end('<p>Hello Server!</p>');
})
.listen(8080, () => { // 서버 연결
console.log('8080번 포트에서 서버 대기 중입니다!');
});
createServer ݫࢲ٘ ٍী listen ݫࢲ٘ܳ ࠢҊ ۄী ҕѐೡ ನ ߣഐ৬ ನ োѾ ৮ܐ റ प೯ؼ
ߔ ೣࣻܳ ֍णפ ઁ ੌਸ प೯ೞݶ ࢲߡח ನীࢲ ਃ য়ӝܳ ӝ݀פ
res ёীח res.writeHead৬ res.write res.end ݫࢲ٘о णפ res.writeHeadח ী ೠ ࠁܳ
ӝ۾ೞח ݫࢲ٘ੑפ ߣ૩ ੋࣻ۽ ࢿҕੋ ਃਸ ೞח ਸ ف ߣ૩ ੋࣻ۽ ী ೠ ࠁܳ
ࠁղחؘ బஎ ഋध )5.-ਸ ঌܻҊ णפ ژೠ ೠӖ दܳ ਤ೧ charsetਸ utf-8۽ ೮णפ
ࠁо ӝ۾غח ࠗ࠙ਸ ؊ )FBEFS ۄҊ ࠗܵפ
res.write ݫࢲ٘ ߣ૩ ੋࣻח ۄ۽ ࠁյ ؘఠੑפ Ә )5.- ݽন ޙৌਸ ࠁչ݅
ߡಌܳ ࠁյ ࣻب णפ ژೠ ৈ۞ ߣ ഐ೧ࢲ ؘఠܳ ৈ۞ ѐ ࠁղب ؾפ ؘఠо ӝ۾غח ࠗ࠙ਸ
ࠄޙ #PEZ ۄҊ ࠗܵפ ؊৬ ࠄޙ ীࢲ ࣁ ঌইࠁѷणפ
res.endח ਸ ઙܐೞח ݫࢲ٘ੑפ ݅ড ੋࣻо ݶ Ӓ ؘఠب ۄ۽ ࠁղҊ ਸ ઙܐ
פ ٮۄࢲ ਤ ઁח res.writeীࢲ <h1>Hello Node!</h1> ޙৌਸ res.endীࢲ <p>Hello Server!</
p> ޙৌਸ ۄ۽ ࠁմ റ ઙܐػ Ѫੑפ ࠳ۄח ղਊਸ ߉ইࢲ ۪؊݂פ