woocommerce / woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api
MIT License
276 stars 76 forks source link

Throws exception when using environment variables via dotenv pacakge #62

Open hicreate opened 4 years ago

hicreate commented 4 years ago

I've noticed that using .env files makes the package throw an exception.

I'm setup in an express server, loading env via dotenv. Woo wrapper is working perfectly when I state my URL, key & secret but as soon as I load them into my server via process.env.API_URL or similar then I get an exception, starting with

"URL is required"

hicreate commented 4 years ago

Solved - not an issue with this package.

JohnMarsden24 commented 3 years ago

Had the same issue when trying to deploy to Google Cloud Functions, figured when the environmental variables were being brought in they weren't a valid string so I used a template literal to fix it:

exports.wooCommerce = new WooCommerceRestApi({
  url: `${process.env.WOOCOMMERCE_URL}`,
  consumerKey: `${process.env.WOOCOMMERCE_KEY}`,
  consumerSecret: `${process.env.WOOCOMMERCE_SECRET}`,
  version: "wc/v3",
  axiosConfig: {
    httpsAgent: new https.Agent({ rejectUnauthorized: false }),
  },
});