node-restful-api-tutorial
node-restful-api-tutorial copied to clipboard
Add a controller
I am follow your course. This issue is create when i create a controller.
i got the same error. I think the error is because the functions in controller does not have excess to the req and res actually . I still dont get why it runs in his tutorial video;. Anyway i solve this issue by declaring it in express app object
exports.signup = app.use((req, res) => { console.log(req.body); //res.send("data recieved");
if (req.body.Full_name == "" || req.body.Full_name == undefined) { res.send("Missing Full Name: try Again"); return; } if (req.body.Email == "" || req.body.Email == undefined) { res.send("Missing Email:: Try again"); return; } if (req.body.Password == "" || req.body.Password == undefined) { res.send("Missing Password:: Try again"); return; } if (Evalid.validateEmailAddress(req.body.Email) === -1) { res.send("Incorrect email :: Enter again"); return; } User.findOne({ Email: req.body.Email }).then((user) => { // console.log(user); if (user || user != null) { return res.send("You are already registered..."); } else { let NewUser = new User({ Full_name: req.body.Full_name, Email: req.body.Email, Password: req.body.Password, }); NewUser.save() .then((events) => { res.json({ success: "You are registered:: Go to Login" }); }) .catch((err) => { console.log(err); // res.send("error"); res.end(); }); } }); });