๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 134

[TAVE] 7๊ธฐ ์ „, ํ›„๋ฐ˜๊ธฐ ํ›„๊ธฐ

์˜ค๋Š˜ TAVE ์ „๋ฐ˜๊ธฐ, ํ›„๋ฐ˜๊ธฐ๊ฐ€ ๋๋‚˜๊ณ  ์ปจํผ๋Ÿฐ์Šค๊นŒ์ง€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค! ์ „๋ฐ˜๊ธฐ์—๋Š” JavaScript ์Šคํ„ฐ๋””๋ฅผ ์ง„ํ–‰ํ–ˆ๊ณ  ํ›„๋ฐ˜๊ธฐ์—๋Š” ๋ฐฑ์—”๋“œ-Nodejs ์Šคํ„ฐ๋””๋ฅผ ์ง„ํ–‰ํ–ˆ๋‹ค ๋‚ด๊ฐ€ ์ „์— ์˜ฌ๋ ธ๋˜ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธ€์€ ์Šคํ„ฐ๋””๋ฅผ ํ•˜๋ฉด์„œ ๋‚ด๊ฐ€ ์ •๋ฆฌํ–ˆ๋˜ ๋‚ด์šฉ์ด๊ณ  Nodejs๋„ ์Šคํ„ฐ๋””๋ฅผ ํ•˜๋ฉด์„œ ์ƒํ™œ์ฝ”๋”ฉ์œผ๋กœ ๊ณต๋ถ€ํ–ˆ๋˜ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•œ ๊ฒƒ์ด๋‹ค ์ „๋ฐ˜๊ธฐ์—” ์ƒ์€ ๋ฐ›์ง€ ๋ชปํ–ˆ์ง€๋งŒ ํ›„๋ฐ˜๊ธฐ์—” ์ƒ๋„ ๋ฐ›์•˜๋‹ค!!(์Šคํ„ฐ๋””-2๋“ฑ >.

[์ƒํ™œ์ฝ”๋”ฉ] Node.js ๋ฅผ ์ด์šฉํ•ด ์›น์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ(4)

๊ธ€ ๋ชฉ๋ก ๋งŒ๋“ค๊ธฐ ์ €์žฅ๋œ data๋ฅผ ์ฝ์–ด์˜ค๋Š” ๋ฒ• *GET์— ๋Œ€ํ•œ ๋ผ์šฐํŠธ app.get('/topic', function(req, res){ // get ๋ฐฉ์‹์œผ๋กœ /topic ๋ผ์šฐํŠธ fs.readdir('data', function(err, files){ if(err){ res.status(500).send('Internal Server Error'); } res.render('view', {topics: files}); }) }) ํ…œํ”Œ๋ฆฟ์—”์ง„์„ ์ด์šฉํ•œ๋‹ค app.set('views', './views_file'); app.set('view engine', 'pug'); ์ „ ์ˆ˜์—…์—์„œ ์ž‘์„ฑํ–ˆ๋˜ ์ด ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์•ผ ํ•จ readdir์„ ์ด์šฉํ•ด์„œ data๋ฅผ ์ฝ์–ด์˜จ๋‹ค ๊ทธ๋•Œ callback ํ•จ์ˆ˜๋Š” err์™€ file ๋ชฉ๋ก(f..

[์ƒํ™œ์ฝ”๋”ฉ] Node.js ๋ฅผ ์ด์šฉํ•ด ์›น์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ(3)

์ฟผ๋ฆฌ์ŠคํŠธ๋ง http://a.com/topic?id=1 protocol / domain / path / query string ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์— ๋”ฐ๋ผ ๊ฐ™์€ path์—์„œ๋„ ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋ฅผ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค app.get('/topic', function(req, res){ let topics = [ 'Javascript is...', 'Nodejs is...', 'Express is...' ]; let str = ` JavaScript Nodejs Express ` let output = str + topics[req.query.id]; res.send(output); }); aํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์„ ๋ฐ”๊ฟ”์ค€๋‹ค ๋”๋ณด๊ธฐ app.get('/topic',function(req, res){ let topics = [ '..

[์ƒํ™œ์ฝ”๋”ฉ] Node.js ๋ฅผ ์ด์šฉํ•ด ์›น์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ(2)

๋™๊ธฐํ™” ๋น„๋™๊ธฐํ™” let fs = require('fs'); // Sync console.log('1'); let data = fs.readFileSync('data.txt',{encoding:'utf8'}); console.log(data); //Async console.log('2'); fs.readFile('data.txt', {encoding:'utf8'}, function(err, data){ console.log('3'); console.log(data); }); console.log('4'); Express express๋ฅผ ์„ค์น˜ํ•œ ํ›„! let express = require('express'); let app = express(); app.get('/', function(req, res){ r..

[์ƒํ™œ์ฝ”๋”ฉ] Node.js ๋ฅผ ์ด์šฉํ•ด ์›น์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ(1)

์•„๋ž˜์˜ ๋”๋ณด๊ธฐ๋Š” ์ฒ˜์Œ์œผ๋กœ ๊ฐ•์˜์—์„œ ์ง„ํ–‰ํ•œ ๋ถ€๋ถ„! ๋”๋ณด๊ธฐ ํด๋”๋ฅผ ๋งŒ๋“  ํ›„ hello.js ํŒŒ์ผ์—์„œ alert๋ฅผ ๋„์šฐ๋„๋ก ์ž‘์„ฑ ํ›„ ์ €์žฅ [์œˆ๋„์šฐ์—์„œ] ํ„ฐ๋ฏธ๋„์„ ์—ด ๋• ์œˆ๋„์šฐ ํ‚ค + r cmd๋ฅผ ์„ ํƒ ํ›„ ์—ด๊ณ  cd๋ฅผ ํ†ตํ•ด ํŒŒ์ผ์— ์ ‘๊ทผ dir/w๋กœ ํŒŒ์ผ ๋ชฉ๋ก ํ™•์ธ, ๋ฌด์—‡์ด ์žˆ๋Š”์ง€ ์•Œ๊ณ  ์‹ถ์œผ๋ฉด dir node hello.js๋ฅผ ์ž…๋ ฅํ•˜๋ฉด nodejs๋กœ hello.js ํŒŒ์ผ ์‹คํ–‰ ์•„๋ž˜๋Š” node.js ํ™ˆํŽ˜์ด์ง€์— ๋‚˜์™€์žˆ๋Š” ๊ฐ„๋‹จํžˆ ์„œ๋ฒ„๋ฅผ ๋งŒ๋“œ๋Š” ์ฝ”๋“œ const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res..

[JavaScript] ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ์ •๋ฆฌํ•œ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธํŽธ(6)

9์žฅ ๐ŸŒญํผ๊ณผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๐ŸŒญ ํผ์ด๋ž€? ์‚ฌ์šฉ์ž๊ฐ€ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด ๋†“์€ ์›น ์š”์†Œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ํผ ์š”์†Œ์˜ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๊ณ  ์ •ํ•ด์ง„ ํ˜•์‹์— ๋งž๋Š”์ง€ ํ™•์ธํ•จ ๐ŸŒญํผ ์š”์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๋ฒ• id, class ๊ฐ’์„ ์ด์šฉ ๋”์˜ ์š”์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์ด querySelector(), querySelectorAll() ํ•จ์ˆ˜ ์‚ฌ์šฉ // id document.querySelector("#billingName") // class document.querySelectorAll(".input-box")[2] name ๊ฐ’์„ ์ด์šฉ // ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ• document.ship.shippingName document.forms["ship"].elements["shippingName"] * form ํƒœ๊ทธ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ ‘๊ทผํ•˜..

[JavaScript] ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ์ •๋ฆฌํ•œ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธํŽธ(5)

8์žฅ ๐Ÿ  ๋ฌธ์„œ ๊ฐ์ฒด ๋ชจ๋ธ (DOM) ๐Ÿ  : ์›น ๋ฌธ์„œ์˜ ๋ชจ๋“  ์š”์†Œ๋ฅผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•ด ๋ฌธ์„œ๋ฅผ ํ•ด์„ํ•˜๋Š” ๋ฐฉ๋ฒ• DOM ํŠธ๋ฆฌ - ๊ตฌ์กฐ๊ฐ€ ๋‚˜๋ฌด๐ŸŒณ์ฒ˜๋Ÿผ ์ƒ๊ฒผ๋‹ค ํƒœ๊ทธ๋ฅผ ์š”์†Œ ๋…ธ๋“œ๋กœ ํ‘œํ˜„ ํƒœ๊ทธ๊ฐ€ ํ’ˆ๊ณ  ์žˆ๋Š” ํ…์ŠคํŠธ๋Š” ์ž์‹ ๋…ธ๋“œ์ธ ํ…์ŠคํŠธ ๋…ธ๋“œ๋กœ ํ‘œํ˜„ ํƒœ๊ทธ์˜ ์†์„ฑ์€ ์š”์†Œ๋…ธ๋“œ์˜ ์ž์‹ ๋…ธ๋“œ์ธ ์†์„ฑ ๋…ธ๋“œ๋กœ ํ‘œํ˜„ ์ฃผ์„์€ ์ฃผ์„ ๋…ธ๋“œ๋กœ ํ‘œํ˜„ DOM ํŠธ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์‚ฌ์ดํŠธ! http://software.hixie.ch/utilities/js/live-dom-viewer/ Live DOM Viewer Live DOM Viewer ... Script not loaded. This script puts a function w(s) into the global scope of the test page,..

[JavaScript] ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ์ •๋ฆฌํ•œ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธํŽธ(4)

7์žฅ ๐Ÿฎ๋ฐฐ์—ด Array๐Ÿฎ : ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ•ญ๋ชฉ ์ €์žฅ ๋ฐฐ์—ด ๋งŒ๋“œ๋Š” ๋ฒ• ๋ฆฌํ„ฐ๋Ÿด ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ var A=[] // ๋ฐฐ์—ด ์„ ์–ธ var A=[1, 2, 3] // ์„ ์–ธ๊ณผ ํ• ๋‹น์„ ๋™์‹œ์— Array ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ธ์Šคํ„ด์Šค ๋งŒ๋“ค๊ธฐ var A=new Array(1,2,3); Array ๊ฐ์ฒด์˜ ํ•จ์ˆ˜ length: ์š”์†Œ์˜ ๊ฐœ์ˆ˜ ๋ฐ˜ํ™˜ var A=['1', '2', '3']; A.length; //3 concat: ๋ฐฐ์—ด ์—ฐ๊ฒฐ var A=['1', '2', '3']; var B=['a', 'b', 'c']; A.concat(B); // [1 2 3 a b c] (์ฝค๋งˆ, ๋”ฐ์˜ดํ‘œ ์ƒ๋žต) B.concat(A); // [a b c 1 2 3] (์ฝค๋งˆ, ๋”ฐ์˜ดํ‘œ ์ƒ๋žต) join: ๋ฐฐ์—ด ์š”์†Œ ๋ฌธ์ž์—ด๋กœ ์—ฐ๊ฒฐ var A..

[JavaScript] ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ์ •๋ฆฌํ•œ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธํŽธ(3)

5์žฅ ๐Ÿฎํ•จ์ˆ˜๐Ÿฎ ํ•จ์ˆ˜ ์„ ์–ธ function addNum(a,b){ return a+b; } ํ•จ์ˆ˜ ์„ ์–ธ๊ณผ ํ˜ธ์ถœ ์œ„์น˜์— ๊ด€๊ณ„์—†์ด ๋ชจ๋‘ ์‹คํ–‰๋œ๋‹ค ์ต๋ช… ํ•จ์ˆ˜ var add=function(a,b){ return a+b; } var num1=parseInt(prompt('์ฒซ ๋ฒˆ์งธ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค')); var num2=parseInt(prompt('๋‘ ๋ฒˆ์งธ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค')); //parseInt๋Š” ๋ฌธ์ž์—ด๋กœ ์ž…๋ ฅ๋ฐ›์€ ๊ฒƒ์„ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ var result=add(num1, num2); console.log(sum); ํ•จ์ˆ˜ ์ž์ฒด๊ฐ€ ์‹์ด๊ธฐ ๋•Œ๋ฌธ์— ์ต๋ช… ํ•จ์ˆ˜๋ฅผ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค ์ฆ‰์‹œ ์‹คํ–‰ ํ•จ์ˆ˜ var sum=(function(a,b){ return a+b; }(10,20)); /* ์ด๋ ‡๊ฒŒ๋„ ๊ฐ€๋Šฅ var sum=..

[JavaScript] ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ์ •๋ฆฌํ•œ Do it ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ณธํŽธ(2)

4์žฅ ๐Ÿจ ์กฐ๊ฑด๋ฌธ if(score>60){ alert("ํ†ต๊ณผ"); } else{ alert("์‹คํŒจ"); } ๐Ÿจ ์กฐ๊ฑด ์—ฐ์‚ฐ์ž score>60 ? alert("ํ†ต๊ณผ") : alert("์‹คํŒจ"); ๐Ÿจ falsy ๊ฐ’ 0 ""(๋นˆ ๋ฌธ์ž์—ด) NaN(์ˆซ์ž๊ฐ€ ์•„๋‹˜) unfined(๊ฐ’์ด ํ• ๋‹น๋˜์ง€ ์•Š์Œ) null(์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฐ’) ๐Ÿจ switch๋ฌธ *case ๋’ค์— ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•จ (case๋ฌธ ๋๋‚  ๋•Œ๋งˆ๋‹ค break, ๋งˆ์ง€๋ง‰์— default ๊ผญ ์จ์ฃผ๊ธฐ) switch(num){ case "1": document.write("1๋ฒˆ์„ ์„ ํƒํ•˜์…จ์Šต๋‹ˆ๋‹ค"); break; case "2": document.write("2๋ฒˆ์„ ์„ ํƒํ•˜์…จ์Šต๋‹ˆ๋‹ค"); break; case "3": document.write("3๋ฒˆ์„ ์„ ํƒํ•˜์…จ์Šต๋‹ˆ๋‹ค"); ..