mardi 27 janvier 2015

Request.JS and Node.js Data problems


Vote count:

0




I am new to Node and I am developing an app that uses Request.JS to pull data from a private API. I need the data to be displayed in one of my views. Currently I have Request being required and defined in one of my routes, like so:



var models = require('../models');// Required for sequelize
var express = require('express');// Required for the Express framework
var router = express.Router();
var request = require('request');// For requesting API data

router.get('/', function (req, res) {
request( // Request from API
'http://ift.tt/18pcIB1',
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the return of the api call.
}
})
models.User.findAll({ // $$$-Define User DB call.
}).then(function(users) {
res.render('index', {
title: 'Project Insight',
users: users,
request: request
});
});
})


When this runs, I can see the output of the data in my console, but I wanted to know the best way to have it display in one of my views. Also, should I even have this in my route? Am lost, thanks for any help.



asked 2 mins ago







Request.JS and Node.js Data problems

Aucun commentaire:

Enregistrer un commentaire