본문 바로가기

IT/web24

Node.js] console.log // dir // table .. var person ={name:"ttt", age:321}; console.log(person); console.dir(person); console.log(person.name); console.dir(person.name); console.log(person.age); console.dir(person.age); console.table(person) dir()은 객체의 속성을 확인할 때 사용한다는데 차이점이 왜 안보이지; What's the difference between console.dir and console.log? In Chrome the console object defines two methods that seem to do the same thing: console.log(...).. 2020. 1. 25.
Node.js] 파일 업로드, multer 미들웨어 일반적으로 웹 서버에서 파일 업로드할 때는 multipart 포맷을 사용한다. 클라이언트에서 POST 방식으로 데이터 전송하므로 body-parser 모듈도 필요하다. var storage = multer.diskStorage({ //업로드한 파일 저장할 폴더 지정 destination: function(req,file,callback){ callback(null, 'uploads') }, // 파일이름 중복안되게 현시간(밀리세크단위) 붙여서 파일이름 수정 filename: function(req,file,callback){ callback(null, file.originalname+ Date.now()) } }); var upload = multer({ storage: storage, limits: {.. 2020. 1. 25.
Node.js] 쿠키 설정, 세션 설정 사용자가 로그인한 상태인지 확인할 때 사용한다. 쿠키는 클라이언트 웹에 저장되는 정보이고, 세션은 웹 서버에 저장된다. 쿠키 cookie-parser Parse HTTP request cookies www.npmjs.com 쿠키 설정할 때는 cookie, 쿠키를 읽어올 때는(가져올때는) cookies How to set cookie in node js using express framework? In my application, I need to set a cookie using the express framework.I have tried the following code but it's not setting the cookie. Can anyone help me to do this? var expre.. 2020. 1. 24.
Node.js] body-Parser urlencoded({extended : ~}) body-parser 미들웨어는 클라이언트가 POST 방식으로 요청할 때 본문 영역의 요청 파라미터들을 파싱해서 요청 객체의 body 속성에 넣어준다. var express = require('express'); var bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.unlencoded({extended : false })); urlencoded()에 대한 설명 extended() 옵션 false : 객체 안에 객체를 파싱못함. query-string 모듈 필요함. true : " " ' 파싱가능. qs 모듈 필요함. 관련 예시 및 설명 What does 'extended' mean in express 4.0? I'.. 2020. 1. 23.