I have a piece of code that I use to consume a API
and I use this same snippet in several files. So I created a module to export such a configuration:
'use strict'
// Module to access woocommerce API endpoints
var woocommerceAPI = require('woocommerce-api')
// Load the environment configuration
require('dotenv').config()
module.exports = () => {
return new woocommerceAPI({
url: process.env.URL,
consumerKey: process.env.CONSUMERKEY,
consumerSecret: process.env.CONSUMERSECRET,
version: process.env.VERSION
})
}
When returning the instance of package woocommerceAPI
it should contain the get
function, as follows.
const wc = require('./wc-config')
wc.get('products', (err, data, res) => {
console.log(res)
})
But I only get the message that wc.get
is not a function.