Answered step by step
Verified Expert Solution
Link Copied!

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 './middleware/errorHandler'
Require stack:
- C:\Users\pauli_2wm671y\p.habbecke-us-states\server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object. (C:\Users\pauli_2wm671y\p.habbecke-us-states\server.js:21:22)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain](node:internal/modules/run_main:135:12){
code: 'MODULE_NOT_FOUND',
requireStack: ['C:\\Users\\pauli_2wm671y\\p.habbecke-us-states\\server.js']
}
Node.js v20.12.2
[nodemon] app crashed - waiting for file changes before starting.../ IMPORT SECTION
// Dotenv Import
require("dotenv").config();
// Express Imports
const express = require("express");
const app = express();
// Cors Imports
const cors = require("cors");
const corsOptions = require("./config/corsOptions");
// Path Import
const path = require("path");
// FS Import
const fs = require("fs");
// Middleware Imports
const { logger }= require("./middleware/logEvents");
const errorHandler = require("./middleware/errorHandler");
// Mongoose (MongoDB) Import
const mongoose = require("mongoose");
// Database Connection
const connectDB = require("./config/connectDB");
// Partials Directory
const hbs = require("hbs");
// Port Declaration
const PORT = process.env.PORT ||3000;
const getStates = require('./controllers/statesController');
// DATABASE SECTION
// Connecting to MongoDB
connectDB();
// MIDDLEWARE SECTION
app.use(logger);
app.use(cors(corsOptions));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// STATIC FILE HANDLER
app.use(express.static(path.join(__dirname, "/public")));
app.use("/subdir", express.static(path.join(__dirname, "/public")));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
// ALL ROUTES
app.use("/", require("./routes/root"));
app.use('/states', require('./routes/api/state'));
//404 ROUTES
app.all("*",(req, res)=>{
res.status(404);
if (req.accepts("html")){
res.sendFile(path.join(__dirname, "views", "404.html"));
} else if (req.accepts("json")){
res.json({ error: "404 not found" });
} else {
res.type("txt").send("404 not found");
}
});
// USE ERROR HANDLER
app.use(errorHandler)
mongoose.connection.once("open",()=>{
console.log("Connected to Mongo DB");
app.listen(PORT,()=> console.log(`Server running on port ${PORT}.`));
});

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions