简体   繁体   中英

Uploading objects to Cloudant using NodeJS in Bluemix

I'm trying to save the JSON from the GET request to an object and then upload the object to the Cloudant DB Anyone know what I'm doing wrong?

var request = require("request");
var EventEmitter = require("events").EventEmitter;
var body = new EventEmitter();
var sample = cloudant.db.use('sample')

request("http://ieeexplore.ieee.org/gateway/ipsSearch.jsp?cs=IBM&hc=1000&rs=1001", function(error, response, data) {
body.data = data;
body.emit('update');
sample.insert({ crazy: true }, body.data, function(err, body, header{
 // hmm
});
console.log('hmm');
});

You have a male formatted URL for the request. And the code for inserting in cloudant data base is wrong written:

var request = require("request");
var EventEmitter = require("events").EventEmitter;
var body = new EventEmitter();
var sample = cloudant.db.use('sample')

request("http://ieeexplore.ieee.org/gateway/ipsSearch.jsp?cs=IBM&hc=1000&rs=1001", function(error, response, data) {
        body.data = data;
        body.emit('update');
//implement code for inserting in cloudant db for homework
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM