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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to