feat(request): initial commit
This commit is contained in:
parent
fcff6fb321
commit
a32d60db52
10
README.md
10
README.md
|
@ -1,4 +1,4 @@
|
|||
# sandbox-nade
|
||||
# sandbox-node
|
||||
|
||||
## Table of Contents
|
||||
0. [General](#General)
|
||||
|
@ -6,5 +6,11 @@
|
|||
# General
|
||||
This is the sandbox for projects using node.js.
|
||||
|
||||
* [dload-file-inbuild-packages](./dload-file-inbuild-packages)
|
||||
* [agency-route-count](./ageny-route-count)
|
||||
* [http-get](./http-get)
|
||||
* [ary-this-week](./ary-this-week)
|
||||
* [gtfs-service](./gtfs-service)
|
||||
* [pbf](./pbf)
|
||||
* [request](./request)
|
||||
* [service-overview](./service-overview)
|
||||
* [week-from-obj](./week-from-obj)
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
* enable reading of environment varialble
|
||||
*/
|
||||
require('dotenv').config();
|
||||
|
||||
/*
|
||||
* enable debugging
|
||||
*/
|
||||
const debug=require('debug')('dload');
|
||||
|
||||
/*
|
||||
* set URL constant
|
||||
*/
|
||||
const URL=process.env.URL||'to be configured using environment variable .env';
|
||||
debug('URL: '+URL)
|
||||
|
||||
/*
|
||||
* enable file system access
|
||||
*/
|
||||
const fs = require('fs');
|
||||
|
||||
/*
|
||||
* enable HTTP requests
|
||||
*/
|
||||
const http = require('http');
|
||||
|
||||
debug('process.cwd(): '+process.cwd());
|
||||
//__dirname is an env variable that tells you the absolute path of the directory containing the currently executing file
|
||||
debug('__dirname: '+__dirname);
|
||||
|
||||
//send HTTP GET request
|
||||
http.get(URL,(res) => {
|
||||
const path = `${__dirname}/dload`;
|
||||
debug('path: '+path);
|
||||
//create file
|
||||
const filePath = fs.createWriteStream(path);
|
||||
res.pipe(filePath);
|
||||
filePath.on('finish',() => {
|
||||
filePath.close();
|
||||
console.log('download Completed');
|
||||
})
|
||||
})
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"name": "dload-file-inbuild-packages",
|
||||
"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": {
|
||||
"dotenv": "^8.2.0",
|
||||
"fs": "0.0.1-security",
|
||||
"http": "0.0.1-security"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
## Overview
|
||||
Download file using request.js
|
||||
|
||||
## 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,request
|
||||
```
|
||||
Run the following command in your favorite terminal to start the service in development mode.
|
||||
```
|
||||
npm run dev
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Stefan Begerad <stefan@begerad.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
## Overview
|
||||
Download file using node.js inbuild packges.
|
||||
Download file using request.js
|
||||
|
||||
## Preparation
|
||||
Run the following command in your favorite terminal to install dependenies.
|
||||
|
@ -14,16 +14,9 @@ npm i
|
|||
## Development setup
|
||||
Run the following command in your favorite terminal if you fancy log messages for debugging.
|
||||
```
|
||||
export DEBUG=$DEBUG,dload
|
||||
export DEBUG=$DEBUG,request
|
||||
```
|
||||
Run the following command in your favorite terminal to start the service in development mode.
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
## Production deployment
|
||||
Run the following command in your favorite terminal to start the service for production mode.
|
||||
```
|
||||
npm run start
|
||||
```
|
||||
## Links
|
||||
[source](https://www.geeksforgeeks.org/how-to-download-a-file-using-node-js/)
|
|
@ -0,0 +1,9 @@
|
|||
require('dotenv').config();
|
||||
const debug=require('debug')('request');
|
||||
const url=process.env.URL||'to be configured using environment variable .env';
|
||||
debug('url: '+url)
|
||||
const fs = require('fs');
|
||||
const request = require('request');
|
||||
const dest='connect-top-dhid.zip';
|
||||
request(url).pipe(fs.createWriteStream(dest));
|
||||
debug('done.');
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "request",
|
||||
"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": {
|
||||
"dotenv": "^8.2.0",
|
||||
"fs": "0.0.1-security",
|
||||
"http": "0.0.1-security",
|
||||
"request": "^2.88.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue