I tried to store the JSON data into a variable in node from JSON file which is located at https://data.sfgov.org/resource/wwmu-gmzc.json Tell me what can I do for that?
Thank you in advance!
I tried to store the JSON data into a variable in node from JSON file which is located at https://data.sfgov.org/resource/wwmu-gmzc.json Tell me what can I do for that?
Thank you in advance!
use mongoose npm to save data to mongodb database
use request npm to make http request to url
Make Model :
var mongoose =require('mongoose')
var Schema = mongoose.Schema;
var movieSchema = new Schema({
actor_1: String,
actor_2: String,
actor_3: String,
director: String,
locations: String,
production_company: String,
release_year: String,
title: String,
writer: String,
});
var Movie = mongoose.model('Movie', movieSchema);
in your app.js
var request = require('request');
var data=[];
request('https://data.sfgov.org/resource/wwmu-gmzc.json', function(error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
if(response && response.statusCode==200){
var data=body;
for(var i=0;i<data.length;i++){
var movie=new Movie(data[i]);
movie.save();
}
}
});
npm), do GET call to that Url and store the result into a variable.