为了账号安全,请及时绑定邮箱和手机立即绑定

运行“npm start”时出现循环错误?

运行“npm start”时出现循环错误?

侃侃尔雅 2022-05-26 16:58:45
我正在尝试在我的计算机上本地运行节点应用程序。我npm start在命令行上运行时收到以下错误:npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! node-express@1.0.0 start: `node index`npm ERR! Exit status 1npm 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.这是我的package.json:{  "name": "node-express",  "version": "1.0.0",  "description": "Node Express Examples",  "main": "index.js",  "scripts": {    "test": "echo \"Error: no test specified\" && exit 1",    "start": "node index"  },  "author": "Shilpa Kancharla",  "license": "ISC",  "dependencies": {    "body-parser": "^1.19.0",    "morgan": "^1.10.0"  }}这是我的index.js:const express = require('express');const http = require('http');const hostname = 'localhost';const port = 3000;const app = express();const morgan = require('morgan');app.use(morgan('dev'));app.use(express.static(__dirname + '/public'));const bodyParser = require('body-parser');app.use(bodyParser.json());const dishRouter = require('./routes/dishRouter');const promoRouter = require('./require/promoRouter');const leaderRouter = require('./require/leaderRouter');app.use('/dishes', dishRouter);app.use('/promotions', promoRouter);app.use('/leaders', leaderRouter);app.use((req, res, next) => {    console.log(req.headers);    res.statusCode = 200;    res.setHeader('Content-Type', 'text/html');    res.end('<html><body><h1>This is an Express Server </h1></body></html>');});const server = http.createServer(app);server.listen(port, hostname, () => {    console.log(`Server running at http://${hostname}:${port}/`);});我尝试安装和卸载节点模块,将其名称更改为start,node index.js但node index没有这样的运气。
查看完整描述

1 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

使用这个 package.json


{

  "name": "node-express",

  "version": "1.0.0",

  "description": "Node Express Examples",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1",

    "start": "nodemon index.js"

  },

  "author": "Shilpa Kancharla",

  "license": "ISC",

  "dependencies": {

    "body-parser": "^1.19.0",

    "express": "^4.17.1",

    "http": "0.0.0",

    "morgan": "^1.10.0"

  },

  "devDependencies": {

    "nodemon": "^2.0.2"

  }

}

现在通过运行以下命令运行和更新节点模块


npm i or npm install

您现在可以通过运行以下命令开始


npm start


查看完整回答
反对 回复 2022-05-26
  • 1 回答
  • 0 关注
  • 205 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信