I started a Node.js application to implement Model View Controller. The logic behind the application is relatively simple: 1) I get a JSON dump using a request.get 2) Put the JSON dump in CouchBase db 3) Get only the "id" value from the JSON file 4) Create a table (HTML) in the viewer to print how often I got every "id".
From what I read online, the model is where my data will be. The viewer will have a jade template to generate dynamically the table in HTML (i am using express.js) and the controller is supposed to react on events, to make sure data is received and viewer is updated.
My question is, which operations belong to which? In my case, what is the Model, the Viewer and the Controller supposed to do? Now I have an app.js file, view.jade, and model.js . Is this correct ?
And also, after I get the JSON dump, I connect to the CouchBase but I am unable to set the file since it does not find the key (the dump is valid JSON) using this code:
request.get(url, function(error, response, body){
console.log(body);
try
{JSON.parse(body);
} catch (e){
return -1;
}
});
var couchbase = require('couchbase');
var db = new couchbase.Connection({host: "localhost:8091", bucket: "default"}, function(err) {
if (err) throw err;
db.set({"id"="176"},body, function(err, result) {
if (err) throw err;
});
});