[英]nodemon app crashed - waiting for file changes before starting error after geting response from server
I'm developing a server in Node JS where there are two routes - Login and Signup .我正在 Node JS 中开发一个服务器,其中有两条路线 - Login 和 Signup 。
Whenever I do signup, I am getting response as success and the data is being stored in MongoDB database successfully and then I'm getting [nodemon] app crashed - waiting for file changes before starting... in my console.每当我注册时,我都会收到成功的响应,并且数据成功地存储在 MongoDB 数据库中,然后我的[nodemon] 应用程序崩溃了 - 在开始之前等待文件更改......在我的控制台中。
Note:- "The problem is in signup only not in login".注意:-“问题仅在于注册而不在于登录”。
postSignup() will be called when a user requests for signup which is validated according to schema and inserted in database. postSignup() 将在用户请求注册时调用,该注册根据架构进行验证并插入到数据库中。 I'm providing the code related to signup.我正在提供与注册相关的代码。
signup.js注册.js
const { User } = require("../../models");
const createError = require("http-errors");
const postSignup = (req, res, next) => {
//validation
const validation = User.validate(req.body);
if (validation.error) {
const error = new Error(validation.error.message);
error.statusCode = 400;
return next(error);
}
//check Existence
const user = new User(req.body);
user
.checkExistence()
.then((result) => {
if (result.check) {
const error = new Error(result.message);
error.statusCode = 409;
return next(error);
}
user.save((err) => {
if (err) {
console.log(err);
return next(createError(500));
}
res.status(201).json({
message: "User has been Successfully Created",
});
});
})
.catch((err) => {
next(createError(500));
});
};
module.exports = {
postSignup,
};
User.js用户.js
const { dbCon } = require("../configuration");
const { userValidator, logSchema } = require("../validator");
const { hashSync, compareSync } = require("bcryptjs");
class User {
constructor(userData) {
this.userData = { ...userData };
}
save(cb) {
dbCon("users", (db) => {
try {
const hashPass = hashSync(this.userData["password"], 12);
this.userData["password"] = hashPass;
db.insertOne(this.userData);
cb();
} catch (err) {
cb(err);
}
});
}
checkExistence() {
return new Promise((resolve, reject) => {
dbCon("users", async (db) => {
try {
const user = await db.findOne({
$or: [
{ username: this.userData["username"] },
{ email: this.userData["email"] },
],
});
if (!user) {
resolve({
check: false,
});
} else if (this.userData["username"] === user.username) {
resolve({
check: true,
message: "username already exists",
});
} else if (this.userData["email"] === user.email) {
resolve({
check: true,
message: "email already exists",
});
}
} catch (err) {
reject(err);
}
});
});
}
static validate(userData) {
//console.log(userData);
return userValidator.validate(userData);
}
module.exports = User;
userValidator.js用户验证器.js
const Joi = require("@hapi/joi");
const schema = Joi.object({
username: Joi.string().alphanum().required().min(3).max(15),
email: Joi.string().email().required(),
password: Joi.string()
.pattern(
new RegExp(
"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"
)
)
.message(
"Password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters"
)
.required(),
first_name: Joi.string().required(),
last_name: Joi.string().required(),
});
module.exports = {
schema
};
I faced the same issue.我遇到了同样的问题。 I don't know what was the issue but I tried to change node version in mongo db connect and then used the new connect URL.我不知道是什么问题,但我尝试在 mongo db connect 中更改节点版本,然后使用新的连接 URL。
If it still doesn't work, then try to create new cluster and connect it again with new cluster.如果它仍然不起作用,则尝试创建新集群并将其与新集群重新连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.