221219(월)

김민석·2022년 12월 19일
0

Today I Learned

목록 보기
17/30
post-custom-banner

오전

node-mariadb-react

npm create-react-app node-mariadb-react

nodeproject

backend

console

npm init -y
npm i express mysql mariadb nodemon

index.js생성

// import express from 'express'
const express = require('express')
const app = express()

app.listen(9900, ()=>{
    console.log("Connected to backend!!333");
})

package.json에 start 추가

{
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },
  }
}

front

npx create-react-app .

npm i react-router-dom


교재 600p

오후

// insert 
app.post("/books", (req, res)=>{
    const sql = "insert into books(`title`,`description`,`price`,`cover`) values (?)";
    const values = [
        req.body.title,
        req.body.description,
        req.body.price,
        req.body.cover
    ];

    [
        {
    
            "title": "aaaa",
            "description": "asdasasas",
            "price": 30000,
            "cover": "cover test"
        }
    ]

    db.query(sql,[values], (err, data)=>{
        if(err) return res.json(err)
        return res.json("Books has been create successfuly")
    })
})
// delete
app.delete("/books/:id", (req, res) => {
    let id = req.params.id;
    const sql = "DELETE FROM books WHERE id= ?";
    console.log("id: ", req.params.id);

    db.query(sql, [id], (err, data) => {
    if(err) return res.json(err)
    return res.json("Books has been delete successfuly")

    });
  });
profile
뉴비개발자
post-custom-banner

0개의 댓글