Giter VIP home page Giter VIP logo

express_boilerplate's Introduction

EXPRESS-BOILERPLATE

express / bcrypt / jwt / mysql2

  • .gitignore로 관리해야하는 file, db설정 => config/
  • jwt 토큰 확인과 같이 middleware으로 추가할 사항들 => router/middleware/
  • bcrypt, compare, token 발급과 같이 자주 쓰이는 것 => lib/
  • baseURL선언 => app.js
  • routing 관련 => router
  • 실제 작동 구현 => controller

How to use

  1. git clone
  2. npm install
  3. config dir 아래 dbPool, secret 파일 설정
  4. .gitignore 파일에서 ### Custom ### 아래 config 부분 주석 해제

DB 사용법

일반적인
await res.pool.query(`query문`, [? 들어갈 변수명])

ex) (`SELECT * FROM USERS WHERE user_id = ?;`, [user_id])

transaction 사용시
exports.signupAPI = async(req, res) => {
    const conn = await res.pool.getConnection()
    try{
        await conn.beginTransaction()

        await conn.query(`query문`, [? 들어갈 변수명])

        await conn.commit()
    } catch(e) {
        await conn.rollback()
    } finally {
        await conn.release()
    }
}

middelware 사용법

  • middelware 파일 작성후, 적용할 router 으로 가져오기
  • router.post([path], [middleware], [controller])
  • jwt middleware 사용시, res.user_id에 해당 user_id변수를 넣어 두었기 때문에 controller에서 res.user_id로 user_id를 가져올 수 있음
  • router/normal.js 참고

express_boilerplate's People

Contributors

ujin2021 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.