feat: intial commit

This commit is contained in:
Begerad, Stefan 2021-09-27 12:12:53 -04:00
commit b75b05f8f5
4 changed files with 92 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Overview
This is the sandbox for projects using node.js.

View File

@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2021 Stefan Begerad <stefan@begerad.de>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
## Overview
Download file using node.js inbuild packges.
## 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,dload
```
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/)

View File

@ -0,0 +1,41 @@
/**
* 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');
/*
* send HTTP GET request
*/
http.get(URL,(res) => {
/*
* image will be stored at this place
*/
const path = `${__dirname}/dload`;
const filePath = fs.createWriteStream(path);
res.pipe(filePath);
filePath.on('finish',() => {
filePath.close();
console.log('Download Completed');
})
})

View File

@ -0,0 +1,20 @@
{
"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"
}
}