0

This is my code.

var express = require('express');
    var router = express.Router();
    var WooCommerceAPI = require('woocommerce-api');
    var WooCommerce = new WooCommerceAPI({
      url: 'https://example.ro',
      consumerKey: 'ck_xxxxxxxxxxxxxxxxx',
      consumerSecret: 'cs_xxxxxxxxxxxxxxxx',
      wpAPI: true,
      version: 'wc/v1'
    });
    router.get('/', function(req, res) {
        WooCommerce.get('products', function(err, data, res) {
        console.log(res);    
        }); 
    });

    module.exports = router;

And i cant seem to find a solution to print the json to the route. I do get a the console log in the terminal. I tried res.json(res) inside WooCommerce.get but i get an error(res.json not a function).

Paul Cozma
  • 140
  • 2
  • 10

1 Answers1

1

This is the solution i got working.

var express = require('express');
    var router = express.Router();

    var WooCommerceAPI = require('woocommerce-api');



    var WooCommerce = new WooCommerceAPI({
      url: 'https://example.ro',
      consumerKey: 'ck_xxxxxxxxxxx',
      consumerSecret: 'cs_xxxxxxxxxxxxxxxxxxxx',
      wpAPI: true,
      version: 'wc/v1'
    });
    var response;
    var link = 'products'
    router.get('/product', function(req, res) {  

     WooCommerce.get(link,function (err, data, res) {
         response = res;     
    });
    res.json(JSON.parse(response));
    });
    module.exports = router;
Paul Cozma
  • 140
  • 2
  • 10