Home > Back-end >  Nodemon is not working: nodemon is not loading
Nodemon is not working: nodemon is not loading

Time:11-29

db.js

const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost:27017/?readPreference=primary&appname=MongoDB Compass&ssl=false";

const connectToMongo = ()=>{
    mongoose.connect(mongoURI, ()=>{
        console.log('database connected');
    })
}

module.exports = connectToMongo;

index.js

const connectToMongo = require('./db');
const express = require('express');

connectToMongo();

const app = express();
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

i have checked dependencies installed nodemon using npm i -D nodemon when i typed nodemon .\index.js my live server should run but it is not[you can see the nodemon is not in green color ][1]

CodePudding user response:

The reason is Powershell does not aware of nodemon. Currently nodemon is installed in your project directory.

I would suggest you to a script in package.json

"scripts": {

   "start-nodemon": "nodemon ./index.js"
}

And then run in powershell

npm run start-nodemon
  • Related