반응형
router.post("/postapi", function(req, res) {
res.send('post api')
})
http://localhost:3000/postapi
진입 시, error라고 표시된다.
https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop
Postman
POSTMAN CHROME IS DEPRECATED DOWNLOAD THE UPDATED POSTMAN NATIVE APPS Postman Chrome is deprecated and is missing essential, new…
chrome.google.com
postman 에서 post, http://localhost:3000/postapi
입력 후, Send 선택 시 값 확인 가능
post 방식은 url 주소로 값을 받는게 아니라 body 안에 값을 받을 수 있다
Body 선택 후, x-www-form-urlencoded 선택하고
key, value 입력
mainRouter.js
router.post("/postapi", function(req, res) {
let body = req.body;
console.log(body)
res.send('post api')
})
postman에서 Send 선택 하면 undefined가 표시된다
app.js
app.use(express.json());
app.use(express.urlencoded());
추가
const express = require('express');
const helmet = require("helmet");
const app = express();
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded());
const mainRouter = require('./router/mainRouter')
app.use('/', mainRouter)
//3000번 포트를 사용 할 것이다
app.listen(3000, function (req, res) {
console.log("port 3000 서버가 실행 되고 있음")
})
postman에서 Send 선택 하면 정상적인 값 출력한다
반응형
'Node.Js' 카테고리의 다른 글
[Node.js] mac에서 MySQL 설치 (access denied for user 'root'@'localhost' using password: yes) (0) | 2023.01.14 |
---|---|
[Node.js] html, css 화면에 표시 (0) | 2023.01.14 |
[Node.js] query (0) | 2023.01.14 |
[Node.js] 크롬 JSON Viewer 설치 (0) | 2023.01.14 |
[Node.js] mainRouter.js (0) | 2023.01.14 |