Node.js 6

[Node.js] mongoose 페이지네이션 구현(pagination)

데이터를 한번에 가져오는게 아니라 나눠서 가져오는것(게시판이나 인스타 게시물) 모듈 설치 npm install mongoose-paginate-v2 model에 내용추가 const mongoosePaginate = require('mongoose-paginate-v2') exampleSchema.plugin(mongoosePaginate) Controller에 내용추가 const index = (req, res, next) => { Example.paginate({}, { page: req.query.page, limit: req.query.limit }) .then(response => { res.json({ response }) }) .catch(error => { res.json({ message:..

Javascript/nodejs 2024.01.02

[Node.js] 사용자 비밀번호 암호화, 로그인, 인증(bcryptjs, jsonwebtoken)

bcyptjs는 데이터 암호화 할때 사용 bcryptjs - npm (npmjs.com) bcryptjs Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.. Latest version: 2.4.3, last published: 7 years ago. Start using bcryptjs in your project by running `npm i bcryptjs`. There are 3373 other projects in the npm registry us www.npmjs.com jsonwebtoken는 회원 인증(로그인) jsonwebtoken - npm (npmjs.com) jsonwebtoken..

Javascript/nodejs 2023.12.31

[Node.js] 파일 업로드 (multer, 예제)

Multer는 파일 업로드를 위해 사용되는 multipart/form-data 를 다루기 위한 node.js 의 미들웨어. 참고 multer/doc/README-ko.md at master · expressjs/multer · GitHub upload.js const path = require('path') const multer = require('multer') var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/') }, filename: function (req, file, cb) { let ext = path.extname(file.originalname) cb(null, Date...

Javascript/nodejs 2023.12.30

Node.js 세팅(express)

1. Node.js 설치 https://nodejs.org/en Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org 2.cmd or PowerShall로 버전확인 node -v 3.npm init으로 설정 엔터 누르면됨 entry point 에서 원하는 파일명 쓰기.(미리 만들었으면 자동으로 바뀜, 처음엔 index.js로 되어있음) 3-1 npm init 오류시 file-Preferences-Settings에 들어감 window profile치고 The default teminal profile on Windows. 밑에를 Command Prompt로 바꾸고 vscode 재시작 잘됨 4. e..

Javascript/nodejs 2023.12.23