When you said you just see 1 object, mean for loop just run 1 time? How
about res object from WooCommerce api? Can you log it to console to see how
many items it return originally?

On Mon, Jan 25, 2016 at 3:07 PM, naijacoder <[email protected]> wrote:

> I'm trying to list all products in WooCommerce using node.js but cant get
> to list all the products to the browser.
> When i run the code i only get to see the first record.
>
> I'm a newbie with node.js
>
> Thanks in Advance
>
> //Lets require/import the HTTP module
> var http = require('http');
>
> //Lets define a port we want to listen to
> const PORT=8080;
>
> //We need a function which handles requests and send response
> function handleRequest(request, response){
>
>     //response.end('It Works!! Path Hit: ' + request.url);
>
>     var WooCommerceAPI = require('woocommerce-api');
>
>     // Initialize the WooCommerceAPI class
>     var WooCommerce = new WooCommerceAPI({
>         //url: 'http://example.com', // Your store url (required)
>     });
>
>     // GET example
>     WooCommerce.get('products', function (err, data, res) {
>         //console.log(res);
>
>         //var fs = require('fs');
>         //var jsonContent = JSON.parse(JSON.stringify(res, null, 4))
>         var jsonContent = JSON.parse(res)
>
>         for (var i = 0; i < jsonContent["products"].length; i++)
>         {
>             var name = jsonContent["products"][i];
>              //This works in console
>             //console.log(name['title']);
>             //console.log(name['id']);
>             //console.log(name['sku']);
>             //console.log(name['regular_price']);
>             response.writeHead(200, {'Content-Type': 'text/plain' });
>             response('It Works!! ' + name['id'] + ' ' + name['title']);
>             //response.end('It Works!! Path Hit: ' + name['id'] + ' ' +
> name['title']);
>
>         }
>         //response.end('It Works!! Path Hit: ' + name['id']);
>     });
>
>    //response.end('It Works!! Path Hit: ' + name['id']);
>
>
> }
>
> //Create a server
> var server = http.createServer(handleRequest);
>
> //Lets start our server
> server.listen(PORT, function(){
>     //Callback triggered when server is successfully listening. Hurray!
>
>
> --
> 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/f5fef765-b6b2-43e1-b459-f47c1624c805%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/f5fef765-b6b2-43e1-b459-f47c1624c805%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Nguyen Hai Duy
Mobile : 0914 72 1900
Skype: nguyenhd2107

-- 
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/CAGOR8-0z6xx0G07YCwANOnqgTF9qO%2BLyLDje2eqWgwRvH2xKmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to