npm 在 node / express 上启动后出现错误
npm ERROR after npm start on node / express
index.js 文件具有以下代码;
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
app.use(morgan('tiny'));
app.use(cors());
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.json({
message: 'Welcome!'
});
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
然后我编辑了 package.json
"main": "index.js",
"scripts": {
"start": "node index.js"
},
依赖版本是:
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.10.0"
}
当我在终端上运行 npm start
时,错误显示如下:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path E:\.....\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'E:\......\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Mamun\AppData\Roaming\npm-cache\_logs20-04-15T10_03_09_445Z-debug.log
我能做什么?请帮忙。提前致谢!
您在此处遇到的错误在该行指定找不到 package.json
文件:
npm ERR! enoent ENOENT: no such file or directory, open
'E:......\package.json'
您需要从 package.json
文件所在的文件夹中 运行 您的 npm start
命令。
index.js 文件具有以下代码;
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
app.use(morgan('tiny'));
app.use(cors());
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.json({
message: 'Welcome!'
});
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
然后我编辑了 package.json
"main": "index.js",
"scripts": {
"start": "node index.js"
},
依赖版本是:
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.10.0"
}
当我在终端上运行 npm start
时,错误显示如下:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path E:\.....\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'E:\......\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Mamun\AppData\Roaming\npm-cache\_logs20-04-15T10_03_09_445Z-debug.log
我能做什么?请帮忙。提前致谢!
您在此处遇到的错误在该行指定找不到 package.json
文件:
npm ERR! enoent ENOENT: no such file or directory, open 'E:......\package.json'
您需要从 package.json
文件所在的文件夹中 运行 您的 npm start
命令。