전체 글
-
IntelliJ / VSCode 단축키ETC 2022. 1. 25. 15:50
IntelliJ 코드 스크린샷 찍기 Ctrl + Alt + Shift + A CodeGlance on/off Ctrl+Shift + G Setting Ctrl + Alt + S Project Structure (Project Settings, Platform Settings) Ctrl + Alt + Shift + S 전체파일 중 특정 문자열 찾기 Ctrl + Shift + F 파일 찾기 Ctrl + N VSCode 모든 코드 블록 접기 Ctrl + K + 0 모든 코드 블록 접펼치기 Ctrl + K + J
-
[GitHub] 이클립스에 있는 프로젝트 깃허브에 올리기ETC 2022. 1. 3. 20:04
git init git branch -m master main git clone __ git remote add origin __ git branch --set-upstream-to=origin/main git add . git commit -m "" git push origin main //혹시 Updates were rejected because the tip of your current branch is behind 라는 오류가 뜬다면 repository 생성 시 readme.md를 생성해서 발생하는 오류이다. git push origin +main
-
[Node.js] AUTH 만들기node.JS 2022. 1. 1. 22:05
페이지 이동 시 로그인이 되어있는 상태인지 CHK 할 수 있어야한다. Client쪽 COOKIE 에 저장된 TOKEN을 DECODE 해서 SERVER로 가져온다. 그러기 위해 AUTH를 만든다. request를 받은 후 callback function 하기 전 중간에서 'auth' 받아오기 middleware/auth.js 만들기 const { User } = require("../models/User"); //user model 불러오기 let auth = (req,res,next)=>{ //인증처리 //Client Cookie 에서 Token을 가져온다. let token =req.cookies.x_auth; //index.js에서 cookie에 넣을 때 x_auth 라는 이름을 이용하여 넣었다. /..
-
[Node.js] 로그인 / 토큰 생성 with JSON WEB TOKENnode.JS 2021. 12. 31. 23:52
1. login route 만들기 01 데이터베이스에서 요청한 E-mail 찾기 : mongodb 에서 제공하는 findOne 메소드 사용 User.findOne({email:req.body.email},(err,user)=>{ if(!user){ return res.json({ loginSucces:false, message:"제공된 이메일에 해당하는 user가 없습니다." }) } 02 DB 에서 요청한 E-mail 이 있다면 비밀번호가 같은지 확인, 비밀번호까지 같다면 Token 생성 //user.js에서 comparePassword 메소드 만들기 userSchema.methods.comparePassword = function(plainPassword,cb){ //plainPassword를 암호화..
-
[node.js] bcrypt로 비밀번호 암호화하기node.JS 2021. 12. 31. 23:51
1. Bcrypt 를 이용하여 비밀번호를 암호화해줘서 DB에 저장하기 1. bcrypt 다운 npm install bcrypt --save 2.index.js const express = require('express'); const app = express() const port = 8080 //User model 가져오기 const { User } = require("./models/User") //body-parser 가져오기 const bodyParser = require('body-parser') //body-parser 옵션주기 (Server에서 정보를 분석하여 가져올 수 있도록) app.use(bodyParser.urlencoded({extended: true})); //application..
-
[Node.js] Nodemon 설치node.JS 2021. 12. 28. 19:57
코드를 수정하면 server를 껐다가 다시 켜서 확인해야하는 작업이 번거로우니 코드를 수정하면 server 를 자동으로 restart 해주는 모듈을 nodemon 이라고 한다. 1. nodemon 설치 npm install nodemon --save-dev dev를 붙이는 이유는 development mode 와 production mode 중 development mode(local) 일 때만 사용하기 위해서이다. 2. satrt 가 아니라 nodemon으로 시작하기 위해 script 하나 더 만들기 { "dependencies": { "body-parser": "^1.19.1", "express": "^4.17.2", "mongoose": "^6.1.4" }, "scripts": { "start": ..
-
[Node.js] 회원가입 기능 만들기node.JS 2021. 12. 28. 19:35
Client와 Server가 통신하는 방법 Chrome Browser와 같은 Client 에서 아이디와 비밀번호를 입력하여 서버에 보내준다. 1.Body-parser Dependency 다운 body-parser 는 node.js 모듈이다. Client POST request data의 body 로부터 parameter를 편리하게 추출할 수 있다. npm install body-parser --save 2. Register Route 만들기 const express = require('express'); const app = express() const port = 8080 //User model 가져오기 const { User } = require("./models/User") //body-parser..
-
[Node.js] Mongoose schema 만들기node.JS 2021. 12. 28. 18:08
mongoose는 테이블이 없어 오류가 많이 생기는 mongoDB나 nosql을 위해 schema를 도입했다. 사용자가 작성한 schema를 기준으로 데이터를 DB에 넣기 전에 먼저 검사를 하여 기준과 다른 데이터가 있으면 에러를 발생시킨다. 1.schema 만들기 const mongoose = require('mongoose'); //mongoose module 가져오기 const userSchema = mongoose.Schema({ //mongoose를 이용하여 schema 생성 name:{ type: String, maxlength: 50 }, email:{ type: String, trim: true, //빈칸 제거 unique: 1 }, password: { type: String, maxle..