Here all my code giving me error of trigger Uncaught Exception in terminal on creating routes
code file - package.json, index.js , posts.js check import "./" this all good but still giving me error.how to ride of this and what cause of this error
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.11.13",
"nodemon": "^2.0.7"
}
}
import express from "express";
import bodyParser from "body-parser"
import cors from "cors"
import mongoose from "mongoose";
import postRoutes from "./routes/posts"
const app = express();
app.use("/posts", postRoutes);
//Compuslory dependenci
app.use(bodyParser.json({limit:"30mb", extended:"true"}));
app.use(bodyParser.urlencoded({limit:"30mb", extended:"true"}));
app.use(cors());
const CONNECTION_URL = "mongodb+srv://username:[email protected]/<dbname>?retryWrites=true&w=majority";
const PORT = process.env.PORT || 9000;
mongoose.connect(CONNECTION_URL, {useNewUrlParser: true, useUnifiedTopology:true})
.then(() => app.listen(PORT, () => console.log(`server runing on ${PORT}`)))
.catch((err) => console.log(err))
mongoose.set('useFindAndModify', false)
import express from "express";
const router = express.Router();
router.get('/', (req, res) => {
res.send('this dont work')
})
export default router;
question from:
https://stackoverflow.com/questions/65880279/node-express-giving-me-error-module-not-found 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…