我正在尝试在我的计算机上本地运行节点应用程序。我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没有这样的运气。
哈士奇WWW
相关分类