Advertisement
magrega

app.js

Jan 7th, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. app.get("/addword", function(req, res) {
  2.  
  3. res.render("addword");
  4.  
  5. });
  6.  
  7. app.post("/addword", function(req, res){
  8.  
  9. var newWord = new Dicword ({
  10.  
  11. word: req.body.wordInput,
  12. definition: req.body.defInput,
  13. title: req.body.titleInput,
  14. genre: req.body.genreInput,
  15. example: req.body.exInput
  16. });
  17.  
  18.  
  19. Dicword.exists({word: req.body.wordInput}, (function(err, existingDoc){
  20.  
  21. if (existingDoc === null) {
  22.  
  23. newWord.save(function(err){
  24. if (!err){
  25. console.log("add succ");
  26. res.render("addwordSUCC");
  27. }
  28.  
  29. else {console.log(err);}
  30. });
  31. } else {
  32.  
  33. let exists = "This word already exists"
  34. res.render("addwordFAIL", {exists: exists});
  35. }
  36.  
  37.  
  38. }));
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement