I'm new to node.js and I'm trying to migrate the backend of my company from python to node.js
Right now I created a node.js server using express. The route works fine. My company uses WooCommerce, and they have a node.js library. My code is this one:
const WooCommerceAPI = require("woocommerce-api");
class WooCommerceController {
async getOrders(req, res) {
const orders = await WooCommerce.get("orders", function(err, data, res) {
return res;
});
return res.json(orders);
}
}
module.exports = new WooCommerceController();
I know that
WooCommerce.get("orders", function(err, data, res) {
console.log(res);
});
works, because if I execute this function it returns the list of orders of my company, however if I try to put it inside this async await, it returns the status of the WooCommerce API, not the response of the API.
What am I doing wrong?
WooCommerce.get()would need to return a promise to useawait. It is using a callback not promiseWooCommerce.getAsyncserves that purpose, let me check