I am currently in the process of setting up a basic express application using the code below:
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}`)
})
When I run it with nodemon, I encounter the following error:
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
Does anyone have any insights into why this error is occurring? All dependencies are listed in the package.json file.