Hi!

You cannot set metadata.detail using the return value of citifmonlineDetail
function.

You must:

var metadata = {
// initialize, skipping detail
};

// then set the detail using the callback

citifmonlineDetail(link, function (result) {
     metadata.detail = result;
// then in this callback, you can use the console
    console.log("----");
    console.log(metadata); // or console.dir(metadata) or
console.log(JSON.stringify(metadata, null, 4)
});

Angel "Java" Lopez
@ajlopez


On Sun, Dec 6, 2015 at 4:27 PM, wasiu razak <[email protected]> wrote:

> hi , am have tried all possible ways to make this work , but it seem to
> not work
> the idea is pass each ,news item to the citifmonlinedetail() to get the
> detail info and pass to json ,and send to database
>
> var url3 = 'http://citifmonline.com/category/news/';
>
> function citifmonlineDetail(url, callback) {
>
> setTimeout(function() {
> request(url, function(error, response, html) {
>
> var detail = "";
>
> if (!error) {
> $ = cheerio.load(html);
>
> $('.entry p').each(function(index, paragraphs) {
> console.log($(paragraphs).text());
> var a = $(paragraphs).text();
> detail = detail.concat(a + " ");
> });
>
> callback(detail);
> }
>
>
> });
> }, 3000);
> }
>
> request(url3, function(error, response, html) {
> if (!error) {
> $ = cheerio.load(html);
> $('div.post-listing article').each(function(index, listings) {
>
> var image = $(listings).find('.post-thumbnail a img');
> var title = $(listings).find('.post-title a');
>
> var description = $(listings).find('.entry p');
> var link = $(title).attr('href');
>
> // var details =
> var metadata = {
> image: $(image).attr('src'),
> title: $(title).text(),
> url: $(title).attr('href'),
> description: $(description).text(),
> detail:citifmonlineDetail(link, function(result) { // here we pass each
> news item link to get the detail news information
> var value = result;
> return value;
> }),
> };
>
> console.log("---------------------------------------------------------------------------");
> console.log(metadata);
> });
>
> }
> });
>
> running only citifmonlinedetail()
> alone works , but combination of my overall logic return json with only
> the detail object returning  undefined and later spits it out corrupting my
> json object concatenation ,any help is very appreciated
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/1b73e38e-8355-43cb-ac12-c1cc8a24279b%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/1b73e38e-8355-43cb-ac12-c1cc8a24279b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAMs%2BDqJ8tmh94D7quZVN7FnAw0_gyRj6byJN%3DTkHKHQ%3D17p3vw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to