npm ERR. code ELIFECYCLE npm ERR. errno 1 npm ERR: node-express@1.0.0 start:
node server
npm ERR. Exit status 1 npm ERR. npm ERR. Failed at the node-express@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR: A complete log of this run can be found in. npm ERR. /Users/teevee/.npm/_logs/2020-05-30T18_42_30_526Z-debug.log
I haven't had any issues until I had to add routes for partners and promotions in my project. I don't know how to debug this type of error in order to make the needed changes. What can possibly be the issue? I'm still learning. Here is a link: https://github.com/TanishaV842/node-express/tree/master/routes
One of the issues you have is that it looks like you're including code for your routers in multiple places:
// server.js
app.use("/campsites", campsiteRouter);
app.use("/partners", partnerRouter);
app.use("/promotions", promotionRouter);
campsiteRouter.route("/campsites").all(...);
partnerRouter.route("/partners").all(...);
promotionsRouter.route("/promotions").all(...);
There's no need to do that, just do app.use("/campsites", campsiteRouter);
and get rid of the router code inside server.js
.
Second, the code inside of your routers
is incorrect in two ways:
// these are two different routes, so create a separate
// route for `/campsites/:campsiteId`,
// additionally, you don't want to do `/campsites/:campsiteId`
// because you specified the `/campsite` route/portion inside of
// your `server.js` file when you did
// `app.use("/campsites", campsiteRouter)`, so only use `/:campsiteId`
// WRONG
campsiteRouter
.route("/campsites")
.all(...)
.get("/campsites/:campsiteId", ...)
// CORRECT
campsiteRouter
.route("/:campsiteId")
.all(...)
.get((req, res) => {
console.log(req.params.campsiteId);
})
.post(...);
Here's your fixed code:
Hope this helps.
It looks like you're mixing up regular router.get()
with router.route().get()
method parameters.
Because you're using the router.route()
method, your:
.get()
.post()
.delete()
call can't pass in a string and a callback. They only except a callback function.
To fix,
change all of the router.route(...).get('<path>', (req, res) => {})
to something like:
router.route(...).get((req, res) => {})
No path parameter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.