简体   繁体   English

bash:nodemon:运行 nodemon app.js 时找不到命令

[英]bash: nodemon : command not found while running nodemon app.js

when im running this code: nodemon app.js it is giving the command not found error.Below is package.json file.当我运行此代码时:nodemon app.js 它给出命令未找到错误。下面是 package.json 文件。

{
  "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 im running npx nodemon app.js the mongo db is giving insertOne(), timeout errors and when im running node app.js the code is working perfectly fine.当我运行 npx nodemon app.js 时,mongo db 给出了 insertOne()、超时错误,当我运行 node app.js 时,代码运行良好。 I just want be able to run nodemon app.js.我只想能够运行 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:当我运行 npx nodemon app.js 或任何其他方法时,它会给出如下错误: MongooseServerSelectionError: connect ECONNREFUSED::1:27017 下面是 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");
    }
  });
});

Run Command "npm install"运行命令“npm install”

if not working run如果不工作运行

"npm i nodemon" “npm 我节点蒙”

Got it I just uninstalled node.js and reinstalled it and then installed nodemon globally.明白了,我刚刚卸载了 node.js 并重新安装了它,然后全局安装了 nodemon。 Now its working fine.现在它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM