最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodemon: app crashed waiting for file changes before starting... on Windows - Stack Overflow

programmeradmin3浏览0评论

I implemented express code with the mongoose database but I have faced "nodemon crushed" error for that I followed the below techniques but still, now I have faced this error.

Node version: v16.14.2 NPM version: 8.5.0

I have followed some steps to solve this issue and that is given below,

  • Open Windows Task Manager is given in the attached file
  • End Task (Node.js JavaScript Runtime) But the problem is not solved!

Here is the code of server.js

const express = require('express')
const mongoose = require('mongoose')
const app = express()
mongoose.connect('mongodb://localhost:27017/my-students');

const studentRoute = require('./api/routes/studentsRoute');
 

//========> Routing Starting
app.use('/api/students', studentRoute);
//========> Routing End


//========> MongoDB Database connection  and Check
const db = mongoose.connection;
db.on('error', (err) =>{
    console.log(err);
})
db.once('open', ()=>{
    console.log("Database connection Established!")
})


const PORT = process.env.PORT || 3000;
app.listen(PORT, () =>{
    console.log(`Server running on PORT @${PORT}`)
})

Windows Task Manager where I end the task by clicking "End Task" of "Node.js JavaScript Runtime" but it was not solved the issue and the Task Manager file attached below,

Error screenshot is given below the attached file,

I implemented express code with the mongoose database but I have faced "nodemon crushed" error for that I followed the below techniques but still, now I have faced this error.

Node version: v16.14.2 NPM version: 8.5.0

I have followed some steps to solve this issue and that is given below,

  • Open Windows Task Manager is given in the attached file
  • End Task (Node.js JavaScript Runtime) But the problem is not solved!

Here is the code of server.js

const express = require('express')
const mongoose = require('mongoose')
const app = express()
mongoose.connect('mongodb://localhost:27017/my-students');

const studentRoute = require('./api/routes/studentsRoute');
 

//========> Routing Starting
app.use('/api/students', studentRoute);
//========> Routing End


//========> MongoDB Database connection  and Check
const db = mongoose.connection;
db.on('error', (err) =>{
    console.log(err);
})
db.once('open', ()=>{
    console.log("Database connection Established!")
})


const PORT = process.env.PORT || 3000;
app.listen(PORT, () =>{
    console.log(`Server running on PORT @${PORT}`)
})

Windows Task Manager where I end the task by clicking "End Task" of "Node.js JavaScript Runtime" but it was not solved the issue and the Task Manager file attached below,

Error screenshot is given below the attached file,

Share Improve this question asked Apr 4, 2022 at 5:23 Imdadul HaqueImdadul Haque 1,8558 gold badges28 silver badges52 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 2

The problem is arising from this line

const studentRoute = require('./api/routes/studentsRoute');

check if you have this included in that file

module.exports = router

Reference: TypeError: Router.use() requires middleware function but got a Object

First stop your local server CTRL + C then remove the package.json file, reinstall the package ,json file npm init after start your server its work to me.

npm init
npm start

If you're on windows, restart your machine. This is what worked for me.

发布评论

评论列表(0)

  1. 暂无评论