Last active
February 20, 2017 22:33
-
-
Save jacksonfdam/f37df719c2d41f138a8c66e7fbfd28e4 to your computer and use it in GitHub Desktop.
Exem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save mongodb request request-promise | |
var request = require('request'); | |
var rp = require('request-promise'); | |
var db = require('mongodb').MongoClient; | |
let key = '246bf886104d519a1d2bf62aef1054ff'; | |
router.get('/update-em-cartaz', function(req, res, next) { | |
rp('http://api.themoviedb.org/3/movie/now_playing?page=1&api_key='+key) | |
.then(function (parsedBody) { | |
var jsonData = JSON.parse(parsedBody); | |
db.connect('mongodb://localhost:27017/moviefun', function(err, db) { | |
if (err) { | |
throw err; | |
} | |
db.collection('filmes').insert(jsonData.results); | |
}); | |
res.json({ | |
title:'filmes', | |
movies:jsonData.results | |
}); | |
}) | |
.catch(function (err) { | |
// Crawling failed... | |
}); | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/emcartaz', function(req, res, next) { | |
db.connect('mongodb://localhost:27017/moviefun', function(err, db) { | |
if (err) { | |
console.error(err); | |
} | |
db.collection('filmes').find().limit(100).toArray(function(err, result) { | |
if (err) { | |
console.error(err); | |
} | |
res.render('filmes',{ | |
title:'Em Cartaz', | |
filmes:result | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment