CarbonFight is an OpenSource project. This repository contains backend serverless functions.
"CalculationsCO2e" is an API that allows you to determine the CO2e emissions of a daily action based on the 250 most common CO2e emission factors.
Swagger : API Swagger
Codacy : Codacy
Install Nodejs
# On Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
npm install
Install Firebase CLI
# On Ubuntu
sudo npm install -g firebase-tools
firebase login
Install project dependencies :
# Working directory
cd functions
npm install
npm install express
npm install cors
npm install --save-dev jest
npm install jest supertest express
npm install swagger-ui-express
Configure emulator :
cd functions
firebase emulators:start
Execute project :
firebase serve
http://localhost:5000/documentation/#/
Uncomment code in functions/index.js from line 24 to 28 to configure the server
const port = 3000;
app.listen(port, () => {
console.log(`Le serveur écoute sur le port ${port}...`);
});
Run :
npm run local
Access the local Swagger documentation : http://localhost:3000/documentation/#/
npm test
To update data, follow these steps:
Copy the serviceAccountKey.json file into import folder. Run the following command:
cd import
npm install
npm run data
Connect to your firebase account and run command :
firebase deploy --only functions --project <nomduprojet>
Create firebase account : (https://firebase.google.com/) and connect.
Open terminal :
firebase login
Init the project :
firebase init
Deploy project :
firebase deploy --only functions --project <nomduprojet>