Skip to content

Commit

Permalink
Update axios version and add dotenv for environment vars
Browse files Browse the repository at this point in the history
Upgraded axios to version 1.7.9 and integrated dotenv to manage environment variables. This change supports better configuration management by using .env files, as reflected in the new scripts and .gitignore entries. Additionally, minor code formatting improvements were made in `external-api.js`.
  • Loading branch information
janoliver20 committed Dec 4, 2024
1 parent 17d59c6 commit 08291ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
9 changes: 6 additions & 3 deletions scripts/external-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import process from 'node:process';
import axios from 'axios';
import {v4 as uuidv4} from 'uuid';
import {config} from "dotenv";

config();

const baseUrl = (process.env.BASE_URL ?? "http://localhost:8085")
.replace(/\/*$/, '')
Expand Down Expand Up @@ -39,7 +42,7 @@ const baseDate = new Date().getTime() //- iterations * 60 + 1000
let itemsSent = 0
for (let i = 1; i <= iterations; i++) {
const id = uuidv4()
const date = baseDate + (i-1) * 60 * 1000
const date = baseDate + (i - 1) * 60 * 1000
const c = i < iterations ? bulkSize :
((dataPoints % bulkSize) === 0 ? bulkSize : (dataPoints % bulkSize))

Expand Down Expand Up @@ -72,11 +75,11 @@ for (let i = 1; i <= iterations; i++) {
.then((response) => {
if (response.status < 300) {
console.info(`Sent Bulk ${i} of ${iterations} (${response.status})`, response.data);
return dataBulk.dataPoints.length
return dataBulk.dataPoints.length;
} else if (response.status >= 400) {
console.error(`Sending data failed: ${response.status} - ${response.statusText}`, response.data);
}
return 0
return 0;
})
.catch((err) => {
console.error(`Received ${err}`);
Expand Down
25 changes: 21 additions & 4 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
"private": true,
"type": "module",
"scripts": {
"external-api": "node external-api.js"
"external-api": "node external-api.js",
"external-api:local": "source .env && npm run external-api"
},
"dependencies": {
"axios": "^1.7.8",
"axios": "^1.7.9",
"uuid": "^11.0.3"
},
"devDependencies": {
"dotenv": "^16.4.7"
}
}

0 comments on commit 08291ad

Please sign in to comment.