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

我正在尝试在我的计算机上本地运行节点应用程序。我npm start在命令行上运行时收到以下错误:


npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! node-express@1.0.0 start: `node index`

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.


这是我的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没有这样的运气。


侃侃尔雅
浏览 206回答 1
1回答

哈士奇WWW

使用这个 package.json{&nbsp; "name": "node-express",&nbsp; "version": "1.0.0",&nbsp; "description": "Node Express Examples",&nbsp; "main": "index.js",&nbsp; "scripts": {&nbsp; &nbsp; "test": "echo \"Error: no test specified\" && exit 1",&nbsp; &nbsp; "start": "nodemon index.js"&nbsp; },&nbsp; "author": "Shilpa Kancharla",&nbsp; "license": "ISC",&nbsp; "dependencies": {&nbsp; &nbsp; "body-parser": "^1.19.0",&nbsp; &nbsp; "express": "^4.17.1",&nbsp; &nbsp; "http": "0.0.0",&nbsp; &nbsp; "morgan": "^1.10.0"&nbsp; },&nbsp; "devDependencies": {&nbsp; &nbsp; "nodemon": "^2.0.2"&nbsp; }}现在通过运行以下命令运行和更新节点模块npm i or npm install您现在可以通过运行以下命令开始npm start
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript