221111 Node.js #3

김혜진·2022년 11월 11일
0

Node.js

목록 보기
3/13

Express


Post

webserver.js

app.post('/add', (req, res) => { // 화살표 함수
    res.send('전송완료');
    console.log(req)
})

req: 요청 정보를 담고있음.
console을 찍어보면 너무 방대한 양의 정보가 있다.

npm install body-parser

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended : true})) // 미들웨어

app.post('/add', (req, res) => { // 화살표 함수
    console.log(req.body.title)
    res.send('전송완료');
})


write.html

...
    <h2 class="container mt-4"><strong>글 작성 페이지</strong></h2>
    
    <div class="container mt-3">
      <form action="/add" method="post">
        <div class="form-group">
          <label>오늘의 할일</label>
          <input type="text" name="title" class="form-control">
        </div>
        <div class="form-group">
          <label>날짜</label>
          <input type="text" name="date" class="form-control">
        </div><p></p>
        <button type="submit" class="btn btn-outline-danger">저장</button>
      </form>
    </div>
...


Rest api


api

application programming interface

rest 원칙

  • http: get, post, (put, delete : 별도의 라이브러리 사용)
  1. uniform interface
    /url
  2. client-server 역할 구분
    client : 요청
    server : 응답
  3. stateless : client1의 요청이 client2 요청에 영향을 끼치면 안된다. (의존성이 낮아야 함)
  4. cacheable

데이터베이스


  • 관계형 데이터베이스 : 오라클, mysql, mssql, postgreSQL

  • NoSQL : mongoDB

데이터가 중요한 이유

  • 데이터를 가공해서 다양한 일을 할 수 있기 때문이다.

파일(file)

  • 배우기 쉬움.
  • 모든 운영체제에 파일 기능 제공하기 때문에 어디서나 사용.
  • 이메일, 메신저를 통해 전송 가능.
  • 성능, 보안, 편의성의 한계를 갖음.

데이터베이스(Database)

  • 파일의 한계를 극복한 방식이 데이터베이스이다.
  • 데이터를 안전하고, 편리하고, 빠르게 보관, 사용가능

데이터베이스 본질


Create
Read
Update
Delete

profile
알고 쓰자!

0개의 댓글