Page 212 - Nodejs 교과서 개정2판
P. 212
});
&YQSFTT ݽٕਸ प೯೧ app ߸ࣻী ೡפ झۨझ ղࠗী IUUQ ݽٕ ղغয ਵ۽ ࢲߡ ೡ
ਸ ೡ ࣻ णפ
app.set('port', 포트)۽ ࢲߡо प೯ؼ ನܳ ࢸפ process.env ёী PORT ࣘࢿ ݶ Ӓ чਸ
ࢎਊೞҊ হݶ ӝࠄчਵ۽ ߣ ನܳ ਊೞب۾ غয णפ ۧѱ app.set(키, 값)ਸ ࢎਊ೧ࢲ
ؘఠܳ ೡ ࣻ णפ աী ؘఠܳ app.get(키)۽ оઉৢ ࣻ णפ
app.get(주소, 라우터)ח ࣗী ೠ (&5 ਃ ৢ ٸ যڃ زਸ ೡ ח ࠗ࠙ੑפ ݒѐ߸ࣻ reqח
ਃী ҙೠ ࠁо ٜয ח ёҊ resח ী ҙೠ ࠁо ٜয ח ёੑפ അ GET / ਃ द
ਵ۽ Hello, Expressܳ ࣠פ झۨझীࢲח res.writeա res.end न res.sendܳ ࢎਊೞݶ
ؾפ
GET ਃ ৻ীب POST PUT PATCH DELETE OPTIONSী ೠ ۄఠܳ ਤೠ app.post app.put app.patch ap
p.delete app.options ݫࢲ٘о ઓפ
listenਸ ೞח ࠗ࠙ IUUQ ਢ ࢲߡ৬ زੌפ ীࢲ ࢲߡܳ ҳز೮؍ Ѫҗ زੌೞѱ ನܳ োѾೞҊ ࢲ
ߡܳ प೯פ ನח app.get('port')۽ оઉ৳णפ
콘솔
$ npm start
> learn-express@0.0.1 start C:\Users\zerocho\learn-express
> nodemon app
[nodemon] 2.0.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
3000 번 포트에서 대기 중
IUUQ MPDBMIPTU ਵ۽ ࣘೞݶ җ э ಕо ڴ Ѫੑפ