에러
TypeError: Cannot destructure property 'index' of 'req.body' as it is undefined.
at exports.postModify (/home/cloudcoke/my/playground/router/controllers/board.controller.js:21:11)
at Layer.handle [as handle_request] (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/layer.js:95:5)
at next (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/layer.js:95:5)
at /home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:346:12)
at next (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:280:10)
at Function.handle (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:175:3)
at router (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:47:12)
원인
req.body
객체가 undefined가 나오고 사용하려고 하면 에러가 나왔다.
- 알고보니
app.use
로 사용해야 하는데 app.set
으로 사용하고 있었다.
server.js
app.set(express.urlencoded({ extended: false }));
해결
app.set
을 app.use
로 변경해주면 된다.
app.use(express.urlencoded({ extended: false }));