Top 15 Node Js 게시판 만들기 The 10 Latest Answer

You are looking for information, articles, knowledge about the topic nail salons open on sunday near me node js 게시판 만들기 on Google, you do not find the information you need! Here are the best content compiled and compiled by the https://chewathai27.com/to team, along with other related topics such as: node js 게시판 만들기 Node js CRUD 게시판, nodejs 게시판 오픈소스, node.js mysql 게시판 만들기, node.js 게시판 예제, Node js 블로그 만들기, JavaScript 게시판 만들기, Node js 게시판, node.js 게시판 github


[Node.js] 백엔드 맛보기 | 로그인 회원가입 | 오리엔테이션 | 백엔드의 모든 것
[Node.js] 백엔드 맛보기 | 로그인 회원가입 | 오리엔테이션 | 백엔드의 모든 것


Node.js, Express, MongoDB – CRUD 게시판 만들기(1)

  • Article author: peachsoong.tistory.com
  • Reviews from users: 41196 ⭐ Ratings
  • Top rated: 3.0 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about Node.js, Express, MongoDB – CRUD 게시판 만들기(1) Node.js, Express, MongoDB – CRUD 게시판 만들기(1). 먼지쑹 2020. 7. 11. 16:16. node js의 express, MongoDB를 사용해서 CRUD 게시판을 만들어보자. 이 게시물은. …
  • Most searched keywords: Whether you are looking for Node.js, Express, MongoDB – CRUD 게시판 만들기(1) Node.js, Express, MongoDB – CRUD 게시판 만들기(1). 먼지쑹 2020. 7. 11. 16:16. node js의 express, MongoDB를 사용해서 CRUD 게시판을 만들어보자. 이 게시물은. node js의 express, MongoDB를 사용해서 CRUD 게시판을 만들어보자. 이 게시물은 https://zellwk.com/blog/crud-express-mongodb/ 사이트를 참고하여 쓰여졌습니다! CRUD – Create Read Update Delete 우선적으로..
  • Table of Contents:

티스토리 뷰

기본 세팅

CRUD – READ

CRUD – CREATE

Node.js, Express, MongoDB - CRUD 게시판 만들기(1)
Node.js, Express, MongoDB – CRUD 게시판 만들기(1)

Read More

[nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL)

  • Article author: kong-dev.tistory.com
  • Reviews from users: 21403 ⭐ Ratings
  • Top rated: 3.1 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about [nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL) 위 포스팅에서 만든거에다가,. 회원만 이용가능한 게시판을 만들거다.ㅎ. 2. DB. user table. board table. 이런 식으로 디비를 만들어서 임시데이터 … …
  • Most searched keywords: Whether you are looking for [nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL) 위 포스팅에서 만든거에다가,. 회원만 이용가능한 게시판을 만들거다.ㅎ. 2. DB. user table. board table. 이런 식으로 디비를 만들어서 임시데이터 … 0. 목차 1. 개요 2. DB 3. 파일 쪼개기 4. CRUD 기능개발 5. 후기 1. 개요 2022.02.11 – [경일/nodejs] – [node.js] express-session, mySQL 로그인 기능 구현 [node.js] express-session, mySQL 로그인 기능 구현..
  • Table of Contents:

관련글

댓글1

공지사항

최근글

인기글

최근댓글

태그

전체 방문자

[nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL)
[nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL)

Read More

node 게시판 만들기 정리(2021.03.25)

  • Article author: junhee916.tistory.com
  • Reviews from users: 18983 ⭐ Ratings
  • Top rated: 3.9 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about node 게시판 만들기 정리(2021.03.25) 그리고 코드를 입력하기 전에 셋팅할 것이 무엇인 지 확인을 해봤다. 1. npm init -y // package.json. 2. npm install express // express. 3. npm … …
  • Most searched keywords: Whether you are looking for node 게시판 만들기 정리(2021.03.25) 그리고 코드를 입력하기 전에 셋팅할 것이 무엇인 지 확인을 해봤다. 1. npm init -y // package.json. 2. npm install express // express. 3. npm … 54.180.30.250 http://54.180.30.250/ 54.180.30.250 처음에 비지니스 로직을 구성할 때 페이지는 메인페이지에 name, password, title, message를 입력을 하면 적었던 내용에 따라 전체조회를 하는 search 페이지..
  • Table of Contents:

Development Layout

development Order

Think

‘TIL’ Related Articles

node 게시판 만들기 정리(2021.03.25)
node 게시판 만들기 정리(2021.03.25)

Read More

‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록

  • Article author: develtraining.tistory.com
  • Reviews from users: 28419 ⭐ Ratings
  • Top rated: 3.2 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about ‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록 ‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록. …
  • Most searched keywords: Whether you are looking for ‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록 ‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록. ‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록
  • Table of Contents:

목록웹프로그래밍Node + Express + Mysql 을 이용한 게시판 만들기 (5)

웹 개발 연습장

'웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기' 카테고리의 글 목록
‘웹프로그래밍/Node + Express + Mysql 을 이용한 게시판 만들기’ 카테고리의 글 목록

Read More


See more articles in the same category here: Chewathai27.com/to/blog.

Node.js, Express, MongoDB

node js의 express, MongoDB를 사용해서 CRUD 게시판을 만들어보자.

이 게시물은

https://zellwk.com/blog/crud-express-mongodb/

사이트를 참고하여 쓰여졌습니다!

CRUD – Create Read Update Delete

우선적으로 node js의 설치가 되어 있어야 한다.

터미널에서 node -v 명령어를 통해 버전을 체크해보자!

<기본 세팅>

1. 작업을 진행할 디렉토리를 하나 만든다.

2. npm init 명령어를 통해 package.json 파일을 생성한다.

모두 enter를 치면 default값으로 세팅되어 파일이 생성된다.

3. touch server.js 명령어를 통해 파일을 생성한다

안에 console.log(‘May Node be with you’) 를 넣어준다.

4. node server.js 명령어로 파일을 생성한다

그러면 터미널 상에 ‘May Node be with you’문구가 출력된다!

‘npm install express –save’

이 명령어를 통해 express를 설치할 수 있다.

실시한 후 package.json을 살펴보면

// package.json “dependencies”: { “express”: “^4.17.1” }

가 생긴것을 볼 수 있다.

const express = require(‘express’); const app = express(); // server와 browser가 연결될때까지 기다리는 것 app.listen(3000, function() { console.log(‘listening on 3000’) })

node server.js를 실행하면 console에 ‘listening on 3000’이라는 문구가 나온다.

그리고 localhost:3000에 접속하면

게 뜨는 것을 확인할 수 있는데, 이것은 브라우저를 통해 express와 통신할 수 있는 상태를 의미하므로 정상적인 결과이다!

–> serverd에서 browser에 아무것도 보내지 않았기 때문에 나오는 결과이다

Express에서, get method를 통해 GET request를 다룰 수 있다.

app.get(endpoint, callback)

endpoint: domain name 다음에 붙는 value

ex) https://zellwk.com/blog/crud-express-mongodb/

이 경우, domain name은 zellwk.com이 되고,

requested endpoint는 zellwk.com 뒤에 따라오는 /blog/crud-express-mongodb가 되는것이다!

callback: requested endpoint와 맞았을 때 서버가 무슨일을 할 지를 말해준다.

two argument 필요로 함 –> request object와 response object

// 두가지는 동일한 일을 수행하는 코드이다 app.get(‘/’, function(req, res) { res.send(“Hello World”) }) app.get(‘/’, (req, res) => { res.send (“Hello World!”) })

// 를 바꿔보자! // sendFile method를 통해 index.html파일로 연결하자 app.get(‘/’, (req, res) => { res.sendFile(__dirname + ‘index.html’) }) //index.html MY APP

May Node and Express be with you.

localhost:3000에 접속하면 index.html의 내용이 나오는 것을 확인할 수 있다!

server를 자동적으로 다시 시작해주는 프로그램

npm install nodemon –save-dev

package.json file에

“scripts”: {

“dev”: “nodemon server.js”

}

를 추가해주면 nodemon server.js로 자동 실행할 수 있다!

실행 방법

npm run dev를 실행하면 자동으로 nodemon server.js를 실행된다.

서버에 POST request를 보낼때 우리는 브라우저에서 CREATE 작업을 수행할 수 있다

–> JavaScript나

tag를 통해 post request 가능!

방법

action attribute 어디에 POST request를 보낼것인가? 이 예시의 경우 /quotes에 보내는 것

method attribute 어떤 방식으로 send request를 브라우저에 보낼 것인가?

name attributes on each element

// index.html에 추가할 내용

// server.js에 추가할 내용 app.post(‘/quotes’, (req, res) => { console.log(“Hellooooooooo”) })

index.html의 form에 내용을 submit 하면 터미널에 Hellooooooo 문구가 출력된다!

npm install body-parser –save

middleware를 의미함.

crud handler앞에 body-parser를 둬서, 정보를 사용하기 쉽게 가공함

const bodyParser= require(‘body-parser’) app.use(bodyParser.urlencoded ({extended: true})) app.get()~~ app.post~~

urlenconded method:

에서 데이터를 추출해 request object에 추가하는 역할

–> 이제

element의 내용을 req.body에서 볼 수 있다!

여기까지의 최종적인 server.js와 index.html의 전체 코드이다.

// 전체 코드 const express = require(‘express’); const app = express(); const bodyParser= require(‘body-parser’) // server와 browser가 연결될때까지 기다리는 것 app.listen(3000, function() { console.log(‘listening on 3000’) }) // body-parser app.use(bodyParser.urlencoded({ extended: true })) // crud handlers // sendFile method를 통해 index.html파일로 연결하자 app.get(‘/’, (req, res) => { res.sendFile(__dirname + ‘/index.html’) }) app.post(‘/quotes’, (req, res) => { console.log(req.body) }) // 전체코드 MY APP

May Node and Express be with you.

다음 포스팅에서는 MongoDB의 사용법에 대해 알아볼 것이다! 😀

[nodejs] 회원만 이용가능 한 게시판 만들기 (feat. mySQL)

728×90

반응형

0. 목차

1. 개요

2. DB

3. 파일 쪼개기

4. CRUD 기능개발

5. 후기

1. 개요

728×90

2022.02.11 – [경일/nodejs] – [node.js] express-session, mySQL 로그인 기능 구현

위 포스팅에서 만든거에다가,

회원만 이용가능한 게시판을 만들거다.ㅎ

2. DB

user table

board table

이런 식으로 디비를 만들어서 임시데이터를 만들었다.

3. 파일쪼개기

쪼갬 ^^

4. CRUD 기능개발

4-1. board list

exports.listGetMid = (req, res) => { const query = `SELECT board._id, board.subject, user.name AS username FROM board JOIN user ON board.author = user._id`; db.query(query, (error, result) => { if (error) return console.log(error); if (result) res.render(‘board/list.html’, { boardList: result }); }); };

쿼리문이 길어져서 선언을 해준뒤에 따로 뺐다.

결과물을 boardList 변수에 담아 html로 전달해주고,

html에선 for문으로 돌려서 db에 있는 내용을 랜더링 해준다

4-2. board view

exports.viewGetMid = (req, res) => { const index = Number(req.query.index); const query = `SELECT board.subject, user.name AS username, board.content FROM board JOIN user ON board.author = user._id WHERE board._id = ${index} `; db.query(query, (error, result) => { if (error) return console.log(error); if (result) { res.render(‘board/view.html’, { posting: result[0] }); } }); };

음 뭐 딱히 설명할게 없다.

굳이굳이 하나 하자면,

내가 board 스키마를 짤때,

_id 값을 INT 로 해놔서,

req.query.index 는 문자열이라 number 로바꿔 주었다.

4-2. board write

exports.writeGetMid = (req, res) => { const { name } = req.session.user; res.render(‘board/write.html’, { username: name }); }; exports.writePostMid = (req, res) => { const { _id } = req.session.user; const { subject, content } = req.body; if (subject === ” || content === ”) { res.send(alertMove(‘/board/write’, ‘공백은 입력이 불가능 합니다’)); } else { const query = `INSERT board (subject, content, author) VALUES (“${subject}”,”${content}”,”${_id}”)`; db.query(query, (error, result) => { if (error) return console.log(error); if (result) res.redirect(`/board/view?index=${result.insertId}`); }); } };

get 요청이 왔을때는 로그인된 아이디를 html 로 전송해주었다.

이렇게 작성자에 수정할수 없게끔 만들어주고 싶었음 ㅎ

POST 요청은 우선 제목과 내용에 모두 아무런 내용도 입력되지 않으면, 디비에 등록이 안되게끔 처리했다.

그리고 글쓰기 버튼을 누르면 디비에 내용이 등록되고, 내가쓴 글의 뷰 페이지로 이동을 하게끔 해야했는데,

uri query 에 넣어줄 값을 고민을 했었다.

근데 console.log 로 result 찍어보니까,

insertId 란 값이있었다.

그게 해당 게시물의 추가된 _id 값이더라 그래서 그걸로 넣어줬다.

4-3. board edit

exports.editGetMid = (req, res) => { const { _id } = req.session.user; const index = Number(req.query.index); const query = `SELECT board._id, board.subject, user.name AS username, board.content FROM board JOIN user ON board.author = user._id WHERE board._id = ${index} `; db.query(query, (error, result) => { if (error) return console.log(error); if (result) { if (result[0]._id === _id) { res.render(‘board/edit.html’, { posting: result[0] }); } else { res.send( alertMove( `/board/view?index=${result[0]._id}`, ‘본인이 작성한 글만 수정할 수 있습니다.’ ) ); } } }); }; exports.editPostMid = (req, res) => { let { _id } = req.body; _id = Number(_id); const { subject, content } = req.body; const query = `UPDATE board SET subject=”${subject}”, content=”${content}” WHERE _id=${_id}`; db.query(query, (error, result) => { if (error) return console.log(error); if (result) { res.send(alertMove(`/board/view?index=${_id}`, ‘글이 수정 되었습니다.’)); } }); };

post 부분은 딱히 특별한게 없지만

get 부분은 조금 신경을 썼다.

현재 로그인이 되어있는 사용자와,

글을 작성한 사용자가 일치하지않는다면, 글수정 버튼을 눌렀을때,

view 페이지로 돌아가고, 본인이 작성한 글만 수정할 수 있다는 경고를 띄워준다.

4-4. board delete

let { index } = req.query; index = Number(index); const query = `SELECT _id ,author FROM board WHERE _id = ${index}`; db.query(query, (error, result) => { if (error) return console.log(error); if (result) { const { _id } = req.session.user; if (result[0].author !== _id) { res.send( alertMove( `/board/view?index=${result[0]._id}`, ‘본인이 작성한 글만 삭제할 수 있습니다.’ ) ); } else { const query = `DELETE FROM board WHERE _id = ${index}`; db.query(query, (error, result) => { if (error) return console.log(error); res.send(alertMove(‘/board/list’, ‘글이 삭제 되었습니다.’)); }); } } });​

음 뭔가 딜리트가 제일 쉬웠는데,

이번엔 제일 어려운것처럼 느껴졌다.

작성된 글의 작성자와, 로그인된 사용자와 일치하는지 확인을 먼저 하고,

일치하면 지우는 건데,

쿼리문을 두번날려야 해서 좀 어렵게 느껴 졌다.

4-5. 로그인 게시판 접속 막기.

이걸 먼저 해버리면 기능개발할 때 좀 걸거쳐서

맨마지막에 하게됐다.

이렇게 해줌 ㅎ

5. 후기

재밋다.. 진짜로..

로그인이랑 게시판이랑 붙이니까 이게 진짜 재밌음

글을 쓸때 자동으로 로그인된 사용자의 name을 입력되게 한다거나,

직접쓴 글만 수정 삭제 할 수있게 한다거나 하는 부분은 진짜 꿀잼이었다.

코딩할맛 난다..!

728×90

반응형

node 게시판 만들기 정리(2021.03.25)

54.180.30.250

처음에 비지니스 로직을 구성할 때 페이지는 메인페이지에 name, password, title, message를 입력을 하면 적었던 내용에 따라 전체조회를 하는 search 페이지를 만들고 해당 내용을 클릭했을 때 수정 및 삭제가 가능한 페이지를 만들어야한다고 했을 때 먼저 어떻게 할건지 그림으로 그려보았다.

그리고 코드를 입력하기 전에 셋팅할 것이 무엇인 지 확인을 해봤다.

1. npm init -y // package.json

2. npm install express // express

3. npm install ejs // ejs

4. npm install mongoose // mongodb

현재 만들고자하는 게시판은 server – express, front – ejs, db- mongodb로 진행하기 때문에 필요한 것만 설치를 한다.

Development L ayout

1. index.js를 만들어서

const boardRouter = require(“./routers/board”); 연결을 하고

app.use(“/api”, [boardRouter]);를 설정함으로써 routers>board.js를 사용할 때 index.js는 ejs 연결 및 port 위주로 담당하고 나머지 기능적인 부분은 board.js에서 관리하게 한다.

2. views folder을 생성하고 그 안에 처음에 계획했던 main.ejs, search.ejs, detail.ejs를 생성한다.

3. schemas folder을 생성하고 처음에는 index.js를 그 안에서 생성해서

const mongoose = require(“mongoose”); const connect = () => { mongoose .connect(“mongodb://localhost:27017/board”, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, ignoreUndefined: true, }) .catch(err => console.log(err)); }; mongoose.connection.on(“error”, err => { console.error(“몽고디비 연결 에러”, err); }); module.exports = connect;

mongodb를 connect를 한다. 이때 먼저 localhost 로 test하는 것이기 때문에 connect경로를

mongodb://localhost:27017/board로 임시 진행을 했지만 추후에 ec2연결하면

Auth Database에 맞게 /admin으로 변경해야한다.

4. schemas>board.js를 생성해서 board.js에 역할은 mongodb에 table및 column을 만드는 역할을 함으로 name, password, title, date, memo colomn을 생성하고 boardId에 역할은 내용을 추가하거나 선택할 때 또는 상세페이지 이동할 때 boardId를 가져와서 사용할 것임으로 required: true, unique: true로 진행해서 중복되지 않게 한다.

const mongoose = require(“mongoose”); const {Schema} = mongoose; const boardSchema = new Schema({ boardId:{ type : Number, required : true, unique : true }, title : { type: String, }, memo : { type: String }, name :{ type: String, }, password : { type: String, }, date : { type: Date } }) module.exports = mongoose.model(“Boards”, boardSchema)

development Order

1. index.js 셋팅

const express = require(‘express’) const app = express() const port = 3000 app.listen(port, ()=>{ console.log(`listening at http://localhost:${port}`) })

먼저 index.js를 셋팅을 한다는 것은 localhost:3000에 파일들을 연결해서 사용할 수 있게 하기 위함이다. 그렇기 때문에 처음에는 express를 이용해서 port 연결 3000으로 셋팅을 하고 파일구성할 때 routers>board.js에 연결하는 코드

const boardRouter = require(“./routers/board”); app.use(“/api”, [boardRouter]);

그리고 ejs를 이용하기 위해서 코드를 넣고

// ejs setting app.set(‘views’, __dirname + ‘/views’); app.set(‘view engine’, ‘ejs’)

mongodb를 이용하기 위해서 require(‘/schemas’)을 connect()한다. 왜냐하면 schemas folder 안에는 mongodb 셋팅이 다 되어있기 때문이다.

const connect = require(‘./schemas’) connect()

마지막으로는 ejs를 localhost:3000을 통해서 이동하기 위해서 경로를 설정한다.

app.get(‘/’, (req, res)=> { res.render(‘main’) }) app.get(‘/search’, (req, res)=> { res.render(‘search’) }) app.get(‘/detail’, (req, res)=>{ res.render(‘detail’) })

index.js 전체코드

const express = require(‘express’) const app = express() const port = 3000 const connect = require(‘./schemas’) connect() const boardRouter = require(“./routers/board”); //body app.use(express.json()) app.use(express.urlencoded({extended:false})) //router app.use(“/api”, [boardRouter]); // ejs setting app.set(‘views’, __dirname + ‘/views’); app.set(‘view engine’, ‘ejs’) app.get(‘/’, (req, res)=> { res.render(‘main’) }) app.get(‘/search’, (req, res)=> { res.render(‘search’) }) app.get(‘/detail’, (req, res)=>{ res.render(‘detail’) }) app.listen(port, ()=>{ console.log(`listening at http://localhost:${port}`) })

2. ejs 기본 form 셋팅

front는 먼저 bulma를 이용해서 script로 활용하기 전에 기본적인 틀을 만들어 놓는다.

bulma에 대한 기본적인 셋팅은

Hello Bulma!

Hello World

My first website with Bulma!

위에 코드를 셋팅하고 필요에 따라서 가져와서 page를 구성을 해놓는다.

내가 만든 기본적인 form은 하단에 모양처럼 셋팅을 했다.

Main Page Search Page Detail Page

3. ejs – express – mongodb 흐름 정리 (FlowChart)

이 코드에 흐름에 맞게 코드를 작성했다. 코드에 전반적인 흐름을 알고 싶다면

github.com/junhee916/memory_git

여기서 2021.03.25에 올렸던 schemas, routers, views를 확인하면 될 것이다.

4. EC2 연결 관련 미흡한 부분 참고

ec2를 진행할 때 프리미어 연결에 대해서는 생략하기로하고 중요한 부분은 mongodb를 연결하기 위해서

robo3T에서 create를 하고 name을 ubuntu 경로는 ec2에서 퍼블릭IPv4 주소로 설정하고 mongodb는 27017로 설정을 해야한다.

git bash에서 mongodb database/id/password 설정을 해주고 localhost에서 진행했던 mongodb가 아닌 ec2에서 돌아갈 mongodb를 만들어야한다.

그리고 schemas>index.js에서 localhost경로로 설정했던 것을 변경해야하고 id랑 password도 입력을 별도로 설정을 해줘야한다.

const mongoose = require(“mongoose”); const connect = () => { mongoose .connect(“mongodb://localhost:27017/admin”, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, ignoreUndefined: true, user: “test”, pass: “test” }) .catch(err => console.log(err)); }; mongoose.connection.on(“error”, err => { console.error(“몽고디비 연결 에러”, err); }); module.exports = connect;

그다음에 filezila에서 변경한 index.js를 업로드를 다시 하고 git bash에서 pm2 stop index.js를 해서 나갔다가 다시 pm2 start index.js 를 하면 변경된 index.js를 가지고 돌아가는 것을 확인할 수 있다.

Think

이번에 웹개발을 하면서 어려웠던 부분이 있었다면

1. api 경로 설정

index.js – app.use(“/api”, [boardRouter]); 이 부분이 board.js 뿐만 아니라 ejs에서 경로 설정할 때도 api는 생략하고 코드 작성하는 줄 알았는데 index.js는 routers>board.js만 api를 작성하지 않아도 /api가 이미 들어있는 것이고 그 외 ejs는 board.js에다가 ajax으로 url 보낼 때는 /api/.. 로 진행한다는 것을 알게 되었다.

2. MongoDB type 설정

mysql을 할 때에는 사실 varchar로만 진행해도 숫자나 문자를 다 사용할 수 있었다. 그런데 mongodb는 문자와 숫자를 구분해서 type을 String or Number로 설정하는 것을 보게 되었다. 여기서 date를 설정할 때에는 숫자와 한글이 혼합되는 경우가 있는데 type을 Date라고 하면 중간에 문자가 들어가도 날짜범위내에서는 저장이 이상 없음을 볼 수 있었다.

password일 경우에는 비밀번호가 **이런 형태로 기입을 하기 때문에 String으로 해야하는 것을 알게 되었다.

3. MongoDB id를 순차적으로 설정

router.post(‘/boards’, async(req, res)=> { console.log(req.body) const {title, name, password, memo, date} = req.body; let boardId = await Boards.find({}).sort(“-boardId”).limit(1); if (boardId.length == 0) { boardId = 1 } else { boardId = boardId[0][‘boardId’] + 1; } await Boards.create({boardId, title, name, password, memo, date}) res.send({result: “success”}) })

여기서 boardId는 post로 보낸 것이 아니지만 boardId를 설정할 때 1씩 증가해서 그 자체로 create로 보낸다는 것이 mysql과 다른 개념이여서 처음에는 이해하기가 어려웠다.

mysql은 auto로 진행되는 것이 mongodb는 조건문으로 Id를 증가해서 post로 보낸 data와 같이 넣어서 Id를 기점으로 정리가 된다는 것을 알 수 있었다.

4. 상세페이지 경로 설정

처음에는 상세페이지를 이동하는 경로를 제대로 이해하지 못했고 전체적이 흐름을 이해하는 게 어려웠다. 그래서 나는 flowchart로 흐름을 정리하니 click을 했을 때 id값을 어떻게 전달하고 그 상세페이지는 어떻게 server에 요청하는 지 알 수 있었다.

5. function name 설정

처음에 mainPage에서 글쓰기 버튼에 name을 onclick=”write()”로 해서 진행을 했는데 code를 맞게 입력해도 계속 오류가 났던 적이 있었다. 그래서 혹시나 function writes()로 하니깐 제대로 실행되는 것을 볼 수 있었다.

구글에 찾아보니 document.write가 있어서 그 영향으로 되지 않았던 것이다. 오류의 범위가 name도 포함된다는 것을 알게 되었다. 하다가 err가 나면 name의 상관관계도 알아봐야겠다.

So you have finished reading the node js 게시판 만들기 topic article, if you find this article useful, please share it. Thank you very much. See more: Node js CRUD 게시판, nodejs 게시판 오픈소스, node.js mysql 게시판 만들기, node.js 게시판 예제, Node js 블로그 만들기, JavaScript 게시판 만들기, Node js 게시판, node.js 게시판 github

Leave a Comment