Express module.js:550 throw err; ^找不到模块

时间:2018-11-30 18:56:33

标签: javascript mongodb express npm server

我正在尝试使用以下代码初始化一个简单的快递应用程序:

const express = require('express');
const app = express()
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const mongoose = require('mongoose');
port = 3000


//creating the db
mongoose.connect('mongodb://localhost:27017/Criptare',{ useNewUrlParser: true,
useCreateIndex: true });
let db = mongoose.connection
db.on('error',console.error.bind(console,"connection error"));

//parsers 
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

//session LATER


//static files
app.use('/static',express.static('public'));

//view engine PUG
app.use('view-engine','pug');

//Routes
const mainRoutes = require('./routes/main')
app.use(mainRoutes)

//error handle
app.use((req,res,next)=>{
    let err = new Error('Looks like the page you were looking for was not found')
    err.status = 404;
    next(err)
})
app.use((err,req,res,next)=>{
    res.locals.error = err
    res.status(err.status);
    res.render('error')
});
app.listen(port,()=>{
    console.log(`No bun serveru ii on pe ip-ul:localhost:${port}`)
})

使用nodemon运行它之后,出现以下错误:

module.js:550
throw err;
^
Cannot find module 'C:\Proiecte code\ON\express\criptare\index.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

任何人都知道为什么我要得到这个吗? 我在package.json中有所有依赖项

1 个答案:

答案 0 :(得分:-2)

我遇到了同样的问题。运行“纱线”解决了该问题