The following code is written in server.js file which is nodejs code
app.get("/api/todos",function(req, res){
todo.find(function(error, todos){
if(error)
res.send(error);
res.json(todos);
});
});
Now I want to call that into my spreadTest.js which is using spread.js, how do I do that?
I'm assuming that your spreadTest.js file is running client side (in a browser) since spread.js is a toolkit for spreadsheets. That means that you will need to send an HTTP GET request to the server running node/server.js. You can create a function in spreadTest.js that performs the request like this:
// Returns JSON object
function getTodos()
{
var url = YOUR-WEBSITE + "/api/todos";
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
return xmlHttp.responseText;
}