[英]How do I fix a node server error, npm ERR! code ELIFECYCLE npm ERR! errno 1?
npm ERR.
npm 错误。 code ELIFECYCLE npm ERR.
代码 ELIFECYCLE npm 错误。 errno 1 npm ERR: node-express@1.0.0 start:
node server
npm ERR.errno 1 npm ERR:node-express@1.0.0 开始:
node server
npm ERR。 Exit status 1 npm ERR.退出状态 1 npm ERR。 npm ERR.
npm 错误。 Failed at the node-express@1.0.0 start script.
在 node-express@1.0.0 启动脚本中失败。 npm ERR!
npm 错误! This is probably not a problem with npm.
这可能不是 npm 的问题。 There is likely additional logging output above.
上面可能还有额外的日志记录 output。
npm ERR: A complete log of this run can be found in. npm ERR.
npm ERR:此运行的完整日志可在 npm ERR 中找到。 /Users/teevee/.npm/_logs/2020-05-30T18_42_30_526Z-debug.log
/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
这是一个链接: 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);
没有必要这样做,只需执行
app.use("/campsites", campsiteRouter);
and get rid of the router code inside server.js
.并摆脱
server.js
中的路由器代码。
Second, the code inside of your routers
is incorrect in two ways:其次,
routers
内部的代码在两个方面不正确:
// 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.看起来您将常规
router.get()
与router.route().get()
方法参数混合在一起。
Because you're using the router.route()
method, your:因为您使用的是
router.route()
方法,所以您的:
.get()
.post()
.delete()
.get()
.post()
.delete()
call can't pass in a string and a callback. call 不能传入字符串和回调。 They only except a callback function.
他们只有一个回调 function。
To fix,修理,
change all of the router.route(...).get('<path>', (req, res) => {})
更改所有
router.route(...).get('<path>', (req, res) => {})
to something like:类似于:
router.route(...).get((req, res) => {})
No path parameter.没有路径参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.