Home > Mobile >  bash: nodemon : command not found while running nodemon app.js
bash: nodemon : command not found while running nodemon app.js

Time:09-17

when i m running this code: nodemon app.js it is giving the command not found error.Below is package.json file.

{
  "name": "whisperauth",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "start": "nodemon app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.0",
    "ejs": "^3.1.8",
    "express": "^4.18.1",
    "mongoose": "^6.6.1",
    "nodemon": "^2.0.20"
  },
  "devDependencies": {},
  "description": ""
}

when i m running npx nodemon app.js the mongo db is giving insertOne(), timeout errors and when i m running node app.js the code is working perfectly fine. I just want be able to run nodemon app.js. when i run npx nodemon app.js or anyother method it gives error like: MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 Below is the connection code for mongodb:

const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require("mongoose");

const app = express();

app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({
  extended:true
}));

mongoose.connect("mongodb://localhost:27017/userDB");

const userSchema = ({
  email: String,
  password: String
});

const User = new mongoose.model("User", userSchema);

//Routes
app.get("/", function(req, res){
  return res.render("home");
});

app.get("/login", function(req, res){
  return res.render("login");
});

app.get("/register", function(req, res){
  return res.render("register");
});

app.post("/register", function(req, res){
  const newUser = new User({
    email: req.body.username,
    password: req.body.password
  });

  newUser.save(function(err){
    if (err){
      console.log(err);
    }else{
      res.render("secrets");
    }
  });
});

CodePudding user response:

Run Command "npm install"

if not working run

"npm i nodemon"

CodePudding user response:

Got it I just uninstalled node.js and reinstalled it and then installed nodemon globally. Now its working fine.

  • Related