Answered step by step
Verified Expert Solution
Question
1 Approved Answer
where is the mistake?? Im geting this error Error: Cannot find module ' . / middleware / errorHandler ' Require stack: - C: Users
where is the mistake??
Im geting this error Error: Cannot find module middlewareerrorHandler
Require stack:
C:Userspauliwmyphabbeckeusstatesserverjs
at Module.resolveFilename node:internalmodulescjsloader::
at Module.load node:internalmodulescjsloader::
at Module.require node:internalmodulescjsloader::
at require node:internalmoduleshelpers::
at Object. C:Userspauliwmyphabbeckeusstatesserverjs::
at Module.compile node:internalmodulescjsloader::
at Module.extensions..js node:internalmodulescjsloader::
at Module.load node:internalmodulescjsloader::
at Module.load node:internalmodulescjsloader::
at Function.executeUserEntryPoint as runMainnode:internalmodulesrunmain::
code: 'MODULENOTFOUND',
requireStack: C:Userspauliwmyphabbeckeusstatesserverjs
Node.js v
nodemon app crashed waiting for file changes before starting... IMPORT SECTION
Dotenv Import
requiredotenvconfig;
Express Imports
const express requireexpress;
const app express;
Cors Imports
const cors requirecors;
const corsOptions requireconfigcorsOptions;
Path Import
const path requirepath;
FS Import
const fs requirefs;
Middleware Imports
const logger requiremiddlewarelogEvents;
const errorHandler requiremiddlewareerrorHandler;
Mongoose MongoDB Import
const mongoose requiremongoose;
Database Connection
const connectDB requireconfigconnectDB;
Partials Directory
const hbs requirehbs;
Port Declaration
const PORT process.env.PORT ;
const getStates requirecontrollersstatesController;
DATABASE SECTION
Connecting to MongoDB
connectDB;
MIDDLEWARE SECTION
app.uselogger;
app.usecorscorsOptions;
app.useexpressurlencoded extended: false ;
app.useexpressjson;
STATIC FILE HANDLER
app.useexpressstaticpathjoindirname, public;
app.usesubdir express.staticpathjoindirname, public;
app.setviews path.joindirname, 'views';
app.setview engine', html;
app.enginehtml requireejsrenderFile;
ALL ROUTES
app.use requireroutesroot;
app.usestates requireroutesapistate;
ROUTES
app.allreq res
res.status;
if reqacceptshtml
res.sendFilepathjoindirname, "views", html;
else if reqacceptsjson
res.json error: not found" ;
else
res.typetxtsend not found";
;
USE ERROR HANDLER
app.useerrorHandler
mongoose.connection.onceopen
console.logConnected to Mongo DB;
app.listenPORT console.logServer running on port $PORT;
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started