skip to Main Content

node:internal/process/esm_loader:94
internalBinding(‘errors’).triggerUncaughtException(
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module ‘D:workMERNmemoryAppserverroutespost’
imported from D:workMERNmemoryAppserverindex.js
Did you mean to import ../routes/post.js?
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:418:11)
at moduleResolve (node:internal/modules/esm/resolve:981:10)
at defaultResolve (node:internal/modules/esm/resolve:1078:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
at ModuleWrap. (node:internal/modules/esm/module_job:79:40)
at link (node:internal/modules/esm/module_job:78:36) {
code: ‘ERR_MODULE_NOT_FOUND’
}

import express from "express"
import bodyParser from "body-parser"
import mongoose from "mongoose"
import cors from "cors"
import postRoutes from "./routes/post"

const app=express();
app.use("/post",postRoutes);

app.use(bodyParser.json({limit:'22mb',extended:true}));
app.use(bodyParser.urlencoded({limit:'22mb',extended:true}));
app.use(cors());

const CONNECTION_URL="mongodb+srv://memoryApp:[email protected]/myFirstDatabase?retryWrites=true&w=majority"
const PORT=process.env.PORT || 5000

mongoose.connect(CONNECTION_URL,{useNewUrlParser:true,useUnifiedTopology:true})
.then(()=>app.listen(PORT,()=>console.log(`Server is running on: ${PORT}`)))
.catch((err)=>console.log(err.message))

2

Answers


  1. Chosen as BEST ANSWER

    In my case, I just import postRouter using "./routes/post" instead of "./routes/post.js". it's funny but it works, can anyone brief me on why?


  2. This import postRoutes from "./routes/post" should instead be import postRoutes from "./routes/post.js".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search