feat(axios-get): initial commit

This commit is contained in:
dancingCycle 2022-05-17 14:39:29 +02:00
parent 86aa454008
commit 0ba33eec8d
6 changed files with 76 additions and 12 deletions

View File

@ -1,8 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Stefan Begerad <stefan@begerad.de>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
## Overview ## Overview
Download file using node.js inbuild packges. Download file using node.js inbuild packges.
@ -14,15 +9,12 @@ npm i
## Development setup ## Development setup
Run the following command in your favorite terminal if you fancy log messages for debugging. Run the following command in your favorite terminal if you fancy log messages for debugging.
``` ```
export DEBUG=$DEBUG,dload export DEBUG=$DEBUG,axios
``` ```
Run the following command in your favorite terminal to start the service in development mode. Run the following command in your favorite terminal to start the service in development mode.
``` ```
npm run dev npm run dev
``` ```
## Production deployment ## Production deployment
Run the following command in your favorite terminal to start the service for production mode.
``` tbc
npm run start
```
## Links

View File

@ -18,7 +18,7 @@ if (process.env.NODE_ENV === 'development') {
rejectUnauthorized: false, rejectUnauthorized: false,
}) })
axios.defaults.httpsAgent = httpsAgent axios.defaults.httpsAgent = httpsAgent
debug('%s RejectUnauthorized is disabled.',process.env.NODE_ENV) debug('%s mode, RejectUnauthorized is disabled.',process.env.NODE_ENV)
} }
run().catch(err => { run().catch(err => {

2
axios-get/.env Normal file
View File

@ -0,0 +1,2 @@
NODE_ENV=development
URL=http://localhost:65534/agency-all

21
axios-get/README.md Normal file
View File

@ -0,0 +1,21 @@
## Overview
tbc
## Preparation
Run the following command in your favorite terminal to install dependenies.
```
npm i
```
## Development setup
Run the following command in your favorite terminal if you fancy log messages for debugging.
```
export DEBUG=$DEBUG,axios
```
Run the following command in your favorite terminal to start the service in development mode.
```
npm run dev
```
## Production deployment
tbc

30
axios-get/index.js Normal file
View File

@ -0,0 +1,30 @@
require('dotenv').config();
const axios = require('axios');
const debug=require('debug')('axios');
const URL=process.env.URL;
debug('URL: '+URL)
run().catch(err => {
debug('run: error')
console.log(err)
});
async function run() {
debug('run:...')
//HTTP GET
let dataGet = await axios.get(
URL
//async example to process responce
// ).then(res => {
// debug('res.data: %s',res.data)
// });
);
debug('data received via GET');
debug('dataGet: %s',dataGet);
debug('dataGet.data.length: %s',dataGet.data.length);
debug('dataGet.data: %s',dataGet.data);
debug('dataGet.data[0].ageny_name: %s',dataGet.data[0].agency_name);
}

19
axios-get/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "axios-get",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Stefan Begerad",
"license": "GPL-3.0",
"devDependencies": {
"nodemon": "^2.0.7"
},
"dependencies": {
"axios": "^0.21.1",
"dotenv": "^8.2.0"
}
}