feat(http-get): initial commit
This commit is contained in:
parent
b75b05f8f5
commit
83dbe121be
10
README.md
10
README.md
|
@ -1,2 +1,10 @@
|
|||
# Overview
|
||||
# sandbox-nade
|
||||
|
||||
## Table of Contents
|
||||
0. [General](#General)
|
||||
|
||||
# General
|
||||
This is the sandbox for projects using node.js.
|
||||
|
||||
* [dload-file-inbuild-packages](./dload-file-inbuild-packages)
|
||||
* [http-get](./http-get)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ADDR='https://jsonplaceholder.typicode.com/users?_limit=2'
|
||||
#ADDR='https://192.168.22.14:65534/agency-all'
|
||||
#ADDR='https://dede-display.vbn.de:42001/ivu-loc'
|
||||
#ADDR='https://soll.vbn.de:65534/stops-all'
|
||||
#ADDR='http://soll.vbn.de/gtfs/frequencies-all'
|
||||
ADDR=http://localhost:65534/agency-all
|
|
@ -0,0 +1,29 @@
|
|||
# HTTP Client in Node.js
|
||||
|
||||
## Table of Contents
|
||||
0. [General](#General)
|
||||
1. [Quick Start Guide](#Quick-Start-Guide)
|
||||
4. [Links](#Links)
|
||||
|
||||
# General
|
||||
|
||||
TODO
|
||||
|
||||
# Quick Start Guide
|
||||
|
||||
## Preparation
|
||||
|
||||
* run the following instruction to install dependenies.
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
## Development setup
|
||||
|
||||
* run the following instruction to start the service in development mode
|
||||
```
|
||||
DEBUG=http-get npm run dev
|
||||
```
|
||||
# Links
|
||||
|
||||
[HTTP Client in Node.js – How to create with Core HTTP](https://bobcares.com/blog/http-client-in-node-js/)
|
|
@ -0,0 +1,24 @@
|
|||
const http = require('http');
|
||||
require('dotenv').config();
|
||||
const DEBUG=require('debug')('http-get');
|
||||
|
||||
const ADDR=process.env.ADDR;
|
||||
DEBUG('ADDR: '+ADDR);
|
||||
let request = http.get(ADDR, (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
console.error(`Did not get an OK from the server. Code: ${res.statusCode}`);
|
||||
res.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('close', () => {
|
||||
console.log('Retrieved all data');
|
||||
console.log(JSON.parse(data));
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "http-get",
|
||||
"description": "HTTP GET request",
|
||||
"version": "0.0.1",
|
||||
"main": "index.js",
|
||||
"author": "Software Ingenieur Begerad <dialog@SwIngBe.de>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4",
|
||||
"dotenv": "^16.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.16"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue