Answer the question
In order to leave comments, you need to log in
How to call model method from NodeJS controller?
The essence of this is a simple data model
exports.CurrencyModel = function(name2,value2,date2){
var name = name2, date = date2, value = value2;
console.log(name)
function getName(){
return name;
}
function getDate(){
return date;
}
function getValue(){
return value;
}
function setName(name1){
name = name1;
}
function setDate(date1){
date = date1;
}
function setValue(value1){
value = value1;
}
}
var http = require('http');
var c = require('../models/CurrencyModel')
exports.CurrencyController = function(){
var options = {
host: 'resources.finance.ua',
path: '/ru/public/currency-cash.json'
};
http.get(options, function(resp){
var str = "";
resp.on('data', function(chunk){
str += chunk;
});
resp.on("end", function(){
var response = JSON.parse(str)
//console.log(response.organizations[0].currencies)
var arra = ["EUR", "RUR", "USD"];
var objC = response.organizations[0].currencies[arra[0]];
var model = new c.CurrencyModel(arra[0], objC.ask, "fs");
console.log(model.getName())
})
}).on("error",function(e){
console.log("Got error:" +e.message)
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question