我遇到这个问题并且我无法解决,据我认为我没有发现任何错误,但我是初学者,所以我不太了解,这里是代码:
[nodemon] starting `node index.js`
module.js:491
throw err;
^
Error: Cannot find module '/www/node-str/index.js'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Function.Module.runMain (module.js:609:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:598:3
[nodemon] app crashed - waiting for file changes before starting...
app.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const router = express.Router();
const index = require('./routes/index');
const products = require('./routes/products')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));
app.use('/', index);
app.use('/products', products);
module.exports = app;
index.js
'use strict';
const express = require('express');
const router = express.Router();
router.get('/', (req, res, next) => {
res.status(200).send({ title: "Node Store API", version: "0.0.1" });
});
module.exports = router;
答案 0 :(得分:-1)
你的package.json是:
"main": "src/app.js"