프로그래밍/Node.js
-
[Node.js, MongoDB] Schema와 Model프로그래밍/Node.js 2022. 3. 28. 19:40
Schema 종류 특징 type String, Number 등 Column의 타입을 지정한다. maxlength 최대 길이 minlength 최소 길이 trim 공백 제거 unique 중복 허용 여부 default 아무 값이 없을 경우 설정할 값 required 필수값 여부 lowercase 소문자로 바꿔준다 uppercase 대문자로 바꿔준다 index 보조 색인 match 패턴이 같지 않으면 저장 x Model 스키마를 감싸고 있는 틀을 의미한다. const mongoose = require('mongoose'); // 스키마 작성 const userSchema = mongoose.Schema({ name: { type: String, maxlength: 50 }, email: { type: Stri..
-
[node.js] NodeJS + React 연동해서 쿠키🍪 교환하기 (크롬)프로그래밍/Node.js 2021. 6. 29. 20:11
현재 프론트는 React, 백은 Node.js를 이용해서 개발하고 있다. 각각 다른 포트를 사용하여 운영 중인데, 로그인 기능을 위해 두 서버간 쿠키를 전송해야 하는 일이 생겼다. 하지만 크로스도메인 문제 때문인지 서버에서 보낸 쿠키가 브라우저에서 나타나지 않았다. 1) CORS 등록 그래서 검색을 해보니 Node에서는 가장 main app(여기서는 server.js)에 cors를 사용해줘야 한다고 한다! // ... const cors = require('cors'); // ... app.use(cors({ origin: true, credentials: true, // 크로스 도메인 허용 methods: ['POST', 'PUT', 'GET', 'OPTIONS', 'HEAD'], })); 리액트 파일..
-
[node.js] 노드 시작하기프로그래밍/Node.js 2021. 2. 7. 22:08
서버 서버는 네트워크를 통해 클라이언트에 정보나 서비스를 제공하는 컴퓨터 또는 프로그램 노트는 자바스크립트 애플리케이션이 서버로서 기능하기 위한 도구를 제공하므로 서버 역할. 자바스크립트 런타임 런타임은 특정 언어로 만든 프로그램들을 실행할 수 있는 환경을 의미한다. 이벤트 기반 이벤트가 발생할 때 미리 지정해둔 작업을 수행하는 방식을 의미한다. 이벤트 기반 시스템에서는 특정 이벤트가 발생할 때 무엇을 할 지 미리 등록해 두어야 함 이벤트 리스너에 콜백 함수를 등록한다, (클릭 이벤트 리스너에 경고창을 띄우는 콜백함수 등록) 이벤트 루프 이벤트 발생 시 호출할 콜백 함수들을 관리하고, 호출된 콜백 함수의 실행 순서를 결정하는 역할을 담당한다. 노드가 종료될 때까지 이벤트 처리를 위한 작업을 반복하므로 루..