본문 바로가기

notAnymore/Udemy API

Occured Errors [TDD, Express]

Cannot overrite model once compiled Mongoose

"https://stackoverflow.com/questions/19051041/cannot-overwrite-model-once-compiled-mongoose"

I brought in "user.spec.js"

"const User = require('../models/user');"

and brought in "auth.js"

"const User = require('../models/User');"

 

defined with diffrent speling. that make occred this error.

Cannot get req.params

when route to another route. we need to define "mergeParams: true".

if not, at the second route, cant get req.params 

// request is POST '/api/v1/course/:courseId/content'

// routes/course.js
// in this route.we can get req.params.courseId 
route.('/api/v1/course/:courseId/content', contentRouter);


// routes/content.js
const router = express.Router({mergeParams: true});  // !!

router
    .route('/')
    .post(createContent);

 

'notAnymore > Udemy API' 카테고리의 다른 글

Course CRUD [TDD, express]  (0) 2020.05.29
Make authentication API with TDD [express]  (0) 2020.05.25