목록JS (25)
taenyLog
------------------ 후위 증가 연산자 > let i = 5 > let result = i++ > result i let i = 0 > ++i i let i = 5 > let result = ++i; // 값 증가후 새 값이 반환되어 result 변수에 저장 > result < 6
post 요청을 받았을때 req.body 접근위해 아래와 같은 코드를 index.js파일에 넣어준다. // 우리가 post 요청을 받으면 그 body의 정보가 필요로 하지만 req.body로 바로 접근 불가 // 할 순 있지만 Undefined 값을 갖는다 .파싱되지않는값 // Express가 미들웨어를 사용하도록 명령해야함. app.use(express.urlencoded({ extended: true })); html Product Name Price (Unit) Select Category Submit
res.send The res.send() function basically sends the HTTP response. The body parameter can be a String or a Buffer object or an object or an Array. Syntax: res.send( [body] ) Parameter: This function accepts a single parameter body that describes the body which is to be sent in the response. Returns: It returns an Object. res.render The res.render() function is used to render a view and sends th..
JavaScript Promises는 비동기 작업을 처리하는 데 사용되는 기능입니다. 기존의 콜백 패턴에서의 단점을 해결하고 비동기 코드를 더욱 효율적으로 관리할 수 있게 해줍니다. Promises를 사용하는 이유는 다음과 같습니다: 1. 비동기 코드 관리: Promises는 비동기 작업을 처리하고 완료되면 결과를 반환하는 데 사용됩니다. 이를 통해 코드를 더욱 쉽게 관리하고, 콜백 지옥(callback hell)과 같은 복잡한 중첩 구조를 피할 수 있습니다. Promises는 비동기 작업의 성공, 실패, 진행 상태 등을 명확하게 처리할 수 있어 코드의 가독성과 유지 보수성을 향상시킵니다. 2. 에러 처리: Promises는 에러 처리를 간편하게 해줍니다. 비동기 작업 중에 발생하는 에러를 catch()..
schema(스키마)는 Mongo의 각기 다른 키 집합을 JavaScript의 다른 타입으로 구조를 짜는 것을 말한다. JS나 기타 언어에서 다른 타입인 데이터를 Mongo로부터 가져오지만 그 언어에 데이터 타입이 있을 수도 있고 없을 수도 있다. 스키마를 정의함으로써 구체화한다. https://mongoosejs.com/docs/guide.html Mongoose v7.3.1: Schemas If you haven't yet done so, please take a minute to read the quickstart to get an idea of how Mongoose works. If you are migrating from 6.x to 7.x please take a moment to read ..
자바스크립트에서 filter는 배열에서 사용하며, 주어진 함수를 만족하는 모든 요소를 모아 새 배열로 반환 .filter() 사용하기 1. .filter()의 () 안에 조건식을 괄호안에 바로 작성 let array = [5,11,9,'string','Hello']; let result = array.filter((value) => value < 10) console.log(result); //array [5, 9] array라는 배열이 있고 10미만의 값 추출을위해 .filter()를 붙히고 괄호안에 필터조건이 되는 함수를 넣었음 . 2. 함수를 만들어 사용 let array = [5,11,9,'string','Hello']; function tenFun(value){ return value < 10 ..

Get 요청 / Post 요청 Get - 요청정보를 가져옴 - get 요청을 보낼 때 따라오는 데이터는 쿼리 문자열에 담김(URL에서 볼 수 있다.) - 백엔드까지 영향을 주진않는다. Post - 정보를 보내거나 올림 - body에 포함 - Json 타입으로 보낼 수 있음 - 생성/ 삭제 / 업데이트 Express Post 경로 정의 Get과 Post를 구별해서 받음 요청 구문 분석하기 다른 포맷으로 데이터를 보낼 수 있다 http://expressjs.com/en/5x/api.html#req.body Express 5.x - API Reference Express 5.x API Note: This is early beta documentation that may be incomplete and is s..

템플레이팅 특정 로직과 HTML 응답 생성을 결합 EJS (Embedded JavaScript) - Node.js에서 많이 사용하는 템플릿엔진 EJS용 Express 구성하기 http://expressjs.com/en/5x/api.html#app.set Express 5.x - API Reference Express 5.x API Note: This is early beta documentation that may be incomplete and is still under development. express() Creates an Express application. The express() function is a top-level function exported by the express modul..