Reading the documented tutorial / code examples for performing a Green hosting check with CO2.js, the code example will cause confusion for anybody working with ES Modules.
With the CommonJS version of the hosting object, check() is a public method, so the following implementation works as per the tutorial:
const { hosting } = require("@tgwf/co2");
const options = {
verbose: false,
userAgentIdentifier: "myGreenApp",
};
hosting.check("google.com", options).then((result) => {
console.log(result);
});
With the ES Module version of the hosting object, the check() method itself is exported, rather than an object containing the check method, requiring the following code:
import { hosting } from "@tgwf/co2";
const options = {
verbose: false,
userAgentIdentifier: "myGreenApp",
};
// Note: hosting.check() isn't a thing; use hosting()
hosting("google.com", options).then((result) => {
console.log(result);
});
I would expect the pattern to remain the same between versions, so perhaps the export line in hosting.js needs to be:
export default { check };
Reading the documented tutorial / code examples for performing a Green hosting check with CO2.js, the code example will cause confusion for anybody working with ES Modules.
With the CommonJS version of the
hostingobject,check()is a public method, so the following implementation works as per the tutorial:With the ES Module version of the
hostingobject, thecheck()method itself is exported, rather than an object containing the check method, requiring the following code:I would expect the pattern to remain the same between versions, so perhaps the export line in hosting.js needs to be: