본문 바로가기

Language/JavaScript

(37)
자바스크립트 Date 에 일, 시간, 분 더하기 var tDate = new Date('2018-07-10 12:30') // 날짜(일) 더하기 tDate.setDate(tDate.getDate()+1) // 시간 더하기 tDate.setHours(tDate.getHours()+6) // 분 더하기 tDate.setMinutes(tDate.getMinutes()+30) console.log(tDate) 출처 https://jhonnywest.tistory.com/107 자바스크립트 Date 에 일, 시간, 분 더하기 1 2 3 4 5 6 7 8 9 10 var tDate = new Date('2018-07-10 12:30') // 날짜(일) 더하기 tDate.setDate(tDate.getDate()+1) // 시간 더하기 tDate.setHours(..
[번역글] JS에서 조건문을 더 낫게 쓰기 위한 꿀팁 5가지 이 글은 Jecelyn Yeen의 5 Tips to Write Better Conditionals in JavaScript라는 글을 한국어로 번역한 글입니다. 원문 링크 JavaScript를 쓸 때는 많은 조건문을 사용합니다. 조건문을 더 보기 좋고, 깔끔하게 쓰는 방법을 알려드리겠습니다. 여러 조건에 함께 맞아야 할 때는 Array.includes를 사용하자. 중첩은 최대한 적게, Return은 최대한 빨리. 기본 파라미터와 비구조화를 사용하자. Switch 대신 Map과 오브젝트를 사용하자. 배열의 전체 조건에는 Array.every, 부분 조건에는 Array.some을 사용하자. 여러 조건에 함께 맞아야 할 때는 Array.includes를 사용하자. 아래의 예제를 봅시다. // 조건문으로 되어있습..
[nodejs]request entity too large 이슈 post로 데이터를 보내는데 56k정도의 데이터를 보냈더니 에러가 남 그래서 ​ var bodyParser = require('body-parser'); app.use(bodyParser.json({limit: '50mb'})); app.use(bodyParser.urlencoded({limit: '50mb', extended: true})); 위와 같이 설정함 module.export 밖에 작성 [출처] [nodejs]request entity too large 이슈|작성자 삽지리 sabjili님의 블로그 : 네이버 블로그 좋은 글과 새로운 이웃을 만나는 곳 blog.naver.com
JavaScript Object[‘key’] vs Object.key 차이 JavaScript 객체의 property를 접근 하는 방법에는 []와 . 을 사용하는 방법이 있습니다. 가령 아래와 같이 a라는 객체가 있다면 속성에 접근하는 방법이 두 가지가 있는거죠 var a = { b : 1, c : 2 }console.log(a["b"] + ' vs ' + a.b) // 1 vs 1 아, 두 가지 방법이 있구나. 헌데 종종 loop 내부에서 a.b와 같이 .을 써서 Property에 접근 시 undefined가 되는 경우를 봤습니다. 그 때는 뭐야? 하고 넘어갔는데 정리 좀 해봤습니다. JS Object property . vs [] nation 먼저 . 표현을 사용한 아래 소스와 결과를 보겠습니다. var a = { “a” : 1, “b-c”: 2, “0d” : 3, “d0”..
header 정보 json 형태로 가져오기 function parseHttpHeaders(httpHeaders) { return httpHeaders .split("\n") .map(x => x.split(/: */, 2)) .filter(x => x[0]) .reduce((ac, x) => { ac[x[0]] = x[1]; return ac; }, {}); } var req = new XMLHttpRequest(); req.open("GET", document.location, false); req.send(null); var headers = parseHttpHeaders(req.getAllResponseHeaders()); console.log(headers);
[nodejs] [ Mongo DB ] mongoose를 이용해 mongoDB 사용하기 > 1. 연결하기 [출처] https://onemooon.tistory.com/entry/Node-JS-module-mongoose%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%B4-mongoDB%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%98%EC%9E%90 기본적인 Mongoose 사용법을 차근차근 포스팅 하고자 한다. 연결하는데는 크게 문제 없었는데 warning 하나가 뜨면서 약간의 connection 수정을 여기에 적어보겠다. 일단 핵심 모듈인 mongoose 를 받는다 123const mongoose = require('mongoose'); //npm i mongoose --save || yarn add mongoose --savecs var 대신에 const를 쓰는 이유는 이..
new Date & ISO String ISO string로컬 브라우저 시간에 맞춘 변환 : new Date(ISO string)* GMT 이하 삭제 : new Date(ISO string).toString().split(" ").slice(0, 5).join(" ")* new Date to ISO String 변환 : new Date('바꾸고 싶은 날짜').toJSON()
[nodejs] mongoose 커넥션 이벤트 함수 // CONNECTION EVENTS // When successfully connected mongoose.connection.on('connected', function () { console.log('Mongoose default connection open to ' + dbURI); }); // If the connection throws an error mongoose.connection.on('error',function (err) { console.log('Mongoose default connection error: ' + err); }); // When the connection is disconnected mongoose.connection.on('disconnected', functi..