54일차 TIL 210525

1. MVC!!!

  • MVC : Model View COntroller : 코드를 여러개로 나눠서 구현하는 것. ex) Express(JS)
  • 스크린샷 2021-05-28 오후 11 06 46
    1. Model : handle data & Interaction with Database
    1. View : what the users see(UI)
    1. Controller : process reqeust, get data from a mode and pass data to the view

2 ORM

  • Object-Relational Mapping // 중계자, 통역사

스크린샷 2021-05-28 오후 11 28 30

  • 자바스크립트 객체를 다루듯이 데이터베이스 의 데이터를 다룰 수 있다.
  • 왜 사용하는가 ? 접근 방법 자체를 프로그래밍 언어 관점에서 할 수 있도록 도와준다. / sql 문 없이도 데이터베이스에 접근할 수 있다.
  • sequelize : promise-based Node.js ORM
  • sql 문 없이 데이터 조회 가능

3. short.ly.MVC 스프린트 하면서 느낀점

  • short.ly 라는 앱은 긴 url 을 짧게 단축시켜 주는 앱이다.
  • 공식문서를 항상 끈기있게 정독해야 한다. 대부분의 정답이 공식문서에 있더라 …
  • 스키마 변경이 있을 떄마다 마이그레이션을 해줘야 한다.
redirect: async (req, res) => {
        let findUrl= await models.url.findOne({ where: { id: req.params.id } })
        await models.url.update({ visits: findUrl.dataValues.visits + 1 }, { where: { id: req.params.id } })
          res.redirect(findUrl.dataValues.url)
          res.status(302).send()
  • async & await 를 사용해서 비동기적으로 해당 함수를 실행시켜준다 - timeouterror 방지 가능
  • 그리고 비동기 함수 마지막에 catch() 를 사용함으로 에러처리를 꼭 해주기
  • util 모듈 사용

Updated: