Skip to content

Green hosting.check() method implementation inconsistent between Node CommonJS and ESM #266

Description

@dotjay

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 };

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions