last day (18 days later) » 

5:35 PM
1
A: Getting empty JSON from mongolab after GET request in node

Shaohao LinThe problem is in your routes.js: app.get('/api/getrandomquestion', function (req, res) { if (req.params.description) { res.json(req.description); } else { res.json(""); } }); req.params.description is undefined. So the if statement failed. If param description is ...

 
I will test this out shortly. Lets assume it works, what if I want to not pass the description but just get a random question? Do I have to have the param :description in my app.get ?
 
In your case, you don't need to pass description as param. When you have the GET request from front-end, just forward to your QuestionService to fetch the random data function with a callback function.
 
I am getting a TypeError: QuestionService.getRandomQuestion is not a function . Since there is really no function called getRandomQuestion.. How can i refer to the function that we meant to refer?
 
This is just an arbitrary function I named it. What is the name of the function that you use to get random question from MongoDB?
 
That's exactly the Question.find... I have in QuestionService.js which is attached to the question
 
5:35 PM
Do you include QuestionService.js in app.js?
 
Yes I do: var QuestionService = require('../public/js/services/QuestionService');
Hey are you online by any chance? :)
 
6:19 PM
Yes
 
6:41 PM
Here now?
 
6:57 PM
hey
YES
Can you post the code of QuestionService? I need to see how you write it to help you.
It will be helpful if you post the entire QuestionService.js code
 
I think i managed to fix it! (:
 
That's good
 
It's working now, I'll accept your answer shortly ok?
 
sure, glad it works! :)
 
Thanks so much for your help
I'll probably post more questions as i continue with this project hehe
 
7:10 PM
You are welcome. Happy hacking
sure, I will take a look then if you post.
 
Thanks! I'll maybe even check if you're here if it's ok.
 
yeah, you can leave any comment, I will constantly check it.
 

  last day (18 days later) »