๋ฐฑ์—”๋“œ 6

[์ƒํ™œ์ฝ”๋”ฉ] NodeJs ํ™œ์šฉํ•˜๊ธฐ(2)

Session : cookie๋ฅผ ์กฐ๊ธˆ ๋” ๊ฐœ์„ ํ•œ ๋ฐฉ๋ฒ• ์ฟ ํ‚ค์™€ ์„œ๋ฒ„์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ž˜ ์กฐํ•ฉํ•ด ์„ธ์…˜์„ ๋งŒ๋“ ๋‹ค cookie๋Š” id๋‚˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋‹ค๋ฃจ๊ธฐ์—๋Š” ์œ„ํ—˜ํ•˜๋‹ค → ๋ณด์•ˆ ๋ฌธ์ œ ์„ธ์…˜์€ ์„œ๋ฒ„๊ฐ€ ์ฟ ํ‚ค ๋ฐฉ์‹์œผ๋กœ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ ์ด๋•Œ ์ฟ ํ‚ค์™€ ๋‹ค๋ฅด๊ฒŒ ์‚ฌ์šฉ์ž์˜ ์‹๋ณ„์ž id ๊ฐ’๋งŒ์„ ์ €์žฅํ•œ๋‹ค → ์‹ค์ œ ๋ฐ์ดํ„ฐ๋Š” ์„œ๋ฒ„์˜ database์— ์ €์žฅ๋˜์–ด ์žˆ๋‹ค ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํด๋ผ์ด์–ธํŠธ๊ฐ€ id๋ฅผ ๊ฐ–๊ณ  ์„œ๋ฒ„์— ์ ‘์†ํ•  ๋•Œ ์„œ๋ฒ„๊ฐ€ ํ•ด๋‹น id ๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” data๋ฅผ ์ฝ์–ด์™€ ์‚ฌ์šฉํ•œ๋‹ค ↓↓ ์‹ค์ œ๋กœ ์„ธ์…˜์˜ set-cookie์—๋Š” connect.sid์˜ ๊ฐ’๋งŒ ์žˆ๊ณ  ์ฟ ํ‚ค์˜ set-cookie์—๋Š” count์˜ ์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค ๋‹ค์‹œ ๋งํ•˜๋ฉด session์€ ํด๋ผ์ด์–ธํŠธ์— ์‚ฌ์šฉ์ž์˜ id ๊ฐ’๋งŒ ์ €์žฅํ•˜๊ณ , cookie๋Š” ํด๋ผ์ด..

[์ƒํ™œ์ฝ”๋”ฉ] Nodejs๋กœ Database ๋‹ค๋ฃจ๊ธฐ(3)

์ด๋ฒˆ ์ˆ˜์—…์—์„œ๋Š” ์ €๋ฒˆ ์ˆ˜์—…๊นŒ์ง€ ์งฐ๋˜ ์ฝ”๋“œ์—์„œ fs๋ฅผ ์ด์šฉํ–ˆ๋˜ ๋ถ€๋ถ„์„ database๋ฅผ ์ด์šฉํ•˜๋„๋ก ๋ฐ”๊ฟ€ ๊ฒƒ์ด๋‹ค! ๊ทธ์ „์— app_file.js์˜ ๋ณต์‚ฌ๋ณธ app_mysql.js๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ ์ €๋ฒˆ๊นŒ์ง€ ์งฐ๋˜ ์ฝ”๋“œ์™€ ๋‹ฌ๋ผ์„œใ…œใ…œ(multer ๋ถ€๋ถ„๋งŒ) ๋”ฐ๋กœ ์ถ”๊ฐ€ํ•ด์คฌ๋‹ค ๋”๋ณด๊ธฐ ์ถ”๊ฐ€ํ•œ multer ๋ถ€๋ถ„ let multer = require('multer'); let _storage =multer.diskStorage({ description: function (req, file, cb){ cb(null, 'uploads/') }, filename: function (req, file, cb){ cb(null, file.originalname); } }) let upload = multer({_storage: _storag..

[์ƒํ™œ์ฝ”๋”ฉ] Nodejs๋กœ Database ๋‹ค๋ฃจ๊ธฐ(1)

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค database๋Š” ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๊ด€๊ณ„ํ˜• database(Oracle, Mysql, Sql server)์™€ ๊ทธ ์™ธ์˜ ๋‹ค์–‘ํ•œ NoSQL๋กœ ๋‚˜๋‰œ๋‹ค. MySQL ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ https://bitnami.com/stack/wamp WAMP Bitnami WAMP Stack provides a complete, fully-integrated and ready to run WAMP development environment. In addition to PHP, MySQL and Apache, it includes FastCGI, OpenSSL, phpMyAdmin, ModSecurity, SQLite, ImageMagick, xDebug, Xcache, OpenLDAP, ModSecurity, bitn..

[์ƒํ™œ์ฝ”๋”ฉ] 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..