This guide will show you how to quickly get started with CO2.js in a variety of ways.
If you're working in a project that already uses NPM, then you can install CO2.js as a dependency.
npm install @tgwf/co2
You can get the latest version of CO2.js using one of the content delivery networks below. This comes in handy if you want to use CO2.js in projects that aren't using Node JS or NPM.
To get started with CO2.js quickly in the browser, you can import the library using Skypack.
import tgwf from 'https://cdn.skypack.dev/@tgwf/co2';
You can find the package at https://unpkg.com/browse/@tgwf/co2@latest/.
You can find the package at https://www.jsdelivr.com/package/npm/@tgwf/co2.
You can also build the CO2.js library from the source code. This allows you to make code changes should you need to do so. To build CO2.js:
Go to the CO2.js repository on GitHub.
Clone or fork the repository.
Navigate to the folder on your machine and run
npm run build in your terminal.
Once the build has finished running, you will find a
/dist folder has been created. Inside you can find:
dist/cjs- A CommonJS compatible build.
dist/esm- An ES Modules compatible build.
dist/iife- An Immediately Invoked Function Expression (IIFE) version of the library.