0.6.1 • Published 2 years ago

sustainability v0.6.1

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

Build Status npm npm download count Coverage Status Known Vulnerabilities MIT License

A new methodology for assessing the Internet carbon footprint and sustainability of digital services. Computes the carbon footprint (CF) index, determines the energy source of servers, the usage of HTTP2.0, WebP image format, lazy loading on images, font subsetting, etc. Effectively generates a customized sustainability report with a set of helpful comments to reduce the CF.

Problematic

Increasing Internet connectivity in everyday life fosters new, or otherwise more energy-intensive, forms of demand that may counterbalance energy savings [1]. As example, the rising of web applications and websites. They provide an engaging user experience with the development of a wide range of functionalities and interactive elements but still, they may have an impact on the environment.

Our solution

Digital Sustainability Audits (DAS) is our solution for an environmentally sustainable transformation of digital resources.

Some of its key features are:

  • Automated
  • Lighting fast
  • Platform agnostic
  • Extensible
  • User & developer friendly

How it works

With the help of several audits or test suits we are able to assess digital sustainability of any service with only one thing: a valid URL.

At this moment, audits are divided into two categories: server and design.

Server audits

Server aspects which are essential for online sustainability.

Design Audits

Targets the website assets that convert code to user consumable content.

Are you ready to try it?

  • Jump right into the demo part and see it by yourself!

Or stay for getting to know better the architecture with our diagrams.

Basic architecture

To better know what exactly does sustainability in the background for each run, please refer to here.

Try it now

User Interface

Visit the site https://audits.digital, enter a URL and wait for the report to be generated for you. That's it.

Install puppeteer (if you don't already have it installed):

npm i puppeteer

Install sustainability locally:

npm i sustainability

Now you can use it on your Node.js application. Take as example the following code:

const { Sustainability } = require("sustainability");

const url = "https://www.example.org";

(async () => {
  const report = await Sustainability.audit(url);
  console.log(report);
})();

sustainability [opts] url Which produces the following report object:

{
  globalScore: 88,
  meta: {
    id: '4c21fbb0-ba35-11ea-bd32-09a6ce997b13',
    url: 'https://www.example.org',
    timing: [ 1593454566154, 1593454568225 ]
  },
  audits: [
    { category: [Object], score: 75, audits: [Object] },
    { category: [Object], score: 100, audits: [Object] }
  ]
}

You can pull the latest trydas/sustainability docker image from this repository

Note that you will also need to have a local installation of Redis or a running docker image.

Environment variables

  • REDIS_HOST (default to 127.0.0.1)
  • REDIS_PORT (default to 6379)
  • FRONTEND_URL (for setting up CORS, default to '*', defaults to null when NODE_ENV=production is set)
  • REDIS_URL (default to unset)

With docker compose

  1. Run docker-compose file in the root docker folder.
cd docker/
docker-compose up -d
  1. Open up a web browser and visit http://localhost:8081

  2. Enter a url and run audits

class: Sustainability

Sustainability module provides a method to run the sustainability audits on a URL.

  • URL <string> A valid and reachable URL to evaluate. Warning: You are responsible for providing a valid URL.
  • settings <Object> Set of configurable settings for the audit. May include the following optional fields:
    • browser <Browser> Your own puppeteer's browser instance. If you set this options, the API won't spawn a browser instance. This may be useful if you want to make use of the launch.connect(wsEndpoint) method to remotely run a headless browser and pass it to the API. Warning: You will be responsible for handling the browser instance.
    • launchSettings <Object> passed to puppeteer.launch. Refer to Puppeteer documentation for more information. Defaults to {}.
    • connectionSettings <Object> Set of configurable connection settings. May include the following fields:
      • maxNavigationTime<number> Specifies a timeout in milliseconds (ms) for all the tasks. Defaults to 60000ms.
      • maxScrollInterval <number> Specifies the scrolling interval in milliseconds (ms) in the function that determines lazy loaded images. Defaults to 30ms.
      • emulatedDevice <Object> Set of emulated device settings. May include the following fields:
        • userAgent <string> A user-agent string.
        • viewport <Object> Set of viewport settings. May include the following fields:
        • name <string> Optional
        • location <Object> Set of location settings. May include the following fields:
          • name <string> The location name.
          • latitude <number> Latitude between -90 and 90
          • longitude <number> Longitude between -180 and 180
          • accuracy<number> Optional non-negative accuracy value
      • coldRun <boolean> Should initialise a cold run to find any potential URL redirect. Defaults to true.
      • streams <boolean> Should push individual audits results as they go. Defaults to false.

A readable stream of audits to pipe from. Used in combination with streams option.

For example:

(async () => {
  Sustainability.auditStream.pipe(process.stdout);
  await Sustainability.audit(url, {
    connectionSettings: { streams: true },
  });
})();

You can enable verbose logging to see the API in action. This is done by setting the DEBUG environmental variable to sustainability:*. or with the -d option in the CLI.

For example:

# Linux
DEBUG=sustainability:* node index.js
# Windows Powershell
$env:DEBUG=sustainability:* node index.js

Contributions are welcomed

This is open-source software. We highly encourage everyone interested to help pushing up this project.\ Core development? Join the team! Make sure you read first the contributions-dev notes.\ Found and issue, visibility, business aspects, sharing your thoughts? Open a new issue\ Sponsoring? Help us to keep the project running in Open Collective.

License

All the code and documents are licensed under MIT.

Useful links

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.13

3 years ago

0.4.14

3 years ago

0.4.11

3 years ago

0.4.12

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.10

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.1

3 years ago

0.4.2

3 years ago

0.3.9

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago