목록전체 글 (91)
Hello World...
nodejs -express 에 lowdb를 연동해보려고 이것저것 해보고 있는데, res.end or res.json 앞에 return 을 작성 안 하면 에러가 발생한다는 점을 발견했다. res.end() 또는 res.josn() 서버 응답 메서드를 실행해도 함수가 종료되지 않는다. 어떻게 보면 너무 당연한 것이지만, 서버 쪽 코드를 짜면서 은근 헷갈리는 부분인 것 같다. return 을 통해 확실히 끝맺음(?) 해주어야 한다. const express = require('express'); const app = express(); const port = 3003; // lowdb setting const low = require('lowdb'); const FileSync = require('lowdb..
예제1) const url = require('url'); const qs = require('querystring'); // WAHTWG parse 방법 const myurl = new url.URL('https://www.naver.com:9000/user?name=mina#hash'); console.log(myurl); // 기존 url parse 방법 const parsedUrl = url.parse( 'https://www.naver.com:9000/user?name=mina&name=sherlock#hash' ); console.log(parsedUrl); const query = qs.parse(parsedUrl.query); console.log(query); const { name } ..

javascript split method 와 join method 를 이용해서 replaceAll method 를 구현해 볼 수 있다. String.prototype.replaceAll = function(searchVal, replaceVal) { return this.split(searchVal).join(replaceVal); }; const str = 'hello'; let changeStr = str.replaceAll('l', '1'); // 'he11o' changeStr; // 'he11o; str; // 'hello' How working split method and join method

postman 에서 json 형식으로 post 를 보내려면 Body , raw 에서 json 형식으로 보내면 된다~
{ name: 'sherlock', address: ' ' // (공백 1문자) } 자바스크립트로 만들어진 위에 객체가 서버로 POST 메서드로 전송되어 저장되었다고 하자. xxx.xx.xx.x?address={주소} get 하고 싶은 경우 스페이스 하나를 넣어도, \0 를 넣어도 겟이 제대로 되지 않는다. URL 인코딩을 해서 넘겨주어야 한다. 그럴 때 encodeURIComponent() 를 사용하면 된다. 공백 문자(\0)는 %20 으로 바뀌어서 들어간다. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Object.create 와 new 가 차이가 없는 줄 알았는데, 사실 큰 차이가 있었다. new Car() 하면 당연히 생성자가 실행이 되고 Object.create(Car.prototype) 을 하면 __proto__ 로 연결만 되는 것 같다. function Car() { this.max = 350; this.auto = true; } Car.prototype.run = function() { console.log('run~~~'); } function ToyCar() { Car.call(this) this.model = "toy"; } ToyCar.prototype = new Car(); ToyCar.prototype.constructor = ToyCar; // ===console==== // C..