运行 'npm start'时出现循环错误?
Cycle error occurs when running '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
更改为 node index.js
,但没有成功。
使用这个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"
}
}
现在 运行 并通过 运行ning 按照命令
更新节点模块
npm i or npm install
您现在可以通过运行执行以下命令
开始
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
更改为 node index.js
,但没有成功。
使用这个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"
}
}
现在 运行 并通过 运行ning 按照命令
更新节点模块npm i or npm install
您现在可以通过运行执行以下命令
开始npm start