TIL - 221009 - study_React

연주·2022년 10월 31일
0

KDT-TIL

목록 보기
27/36

프로젝트를 위한 개발환경셋팅

backend - axios express mysql nodemon
frontend - CRA styled-components react-router-dom nodemon

app.js 기본 셋팅

const express = require("express");
const app = express();

const PORT = 5000;

app.listen(PORT, () => {
  console.log(`express 서버 ${PORT} 실행`);
});

package.json

  "scripts": {
    "dev": "nodemon app"
  },
// 터미널에 nodemon app을 입력하면 서버 작동 시작

MySQL에 테이블 생성한 후, node.js에 MySQL연동

db.js

const mysql = require("mysql2");

// MySQL 연동
const connection = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "1234",
  database: "Test",
});

connection.connect((err) => {
  if (err) throw err;
  console.log("데이터 베이스 접속");
});

module.exports = connection;

거의 한달이 다 되서 적는 것인데, 저렇게 연동을 하고
input 박스에 입력한 정보를 db에 저장하는 연습을 했었다.
그 당시 따라가기 힘들어서,

프론트에서 서버에 데이터 요청하는 방법이라는 유투브 강좌를 보았다.
다음 게시글에 정리해봐야겠다.

profile
성장중인 개발자🫰

0개의 댓글