download a file nodejs
const http = require('http');
const fs = require('fs');
const url = 'www.example.com/image.png'; // link to file you want to download
const path = 'app/assets/my_image_name.xlsx' // where to save a file
const request = http.get(url, function(response) {
if (response.statusCode === 200) {
var file = fs.createWriteStream(path);
response.pipe(file);
}
request.setTimeout(60000, function() { // if after 60s file not downlaoded, we abort a request
request.abort();
});
});const http = require('http');
const fs = require('fs');
const file = fs.createWriteStream("file.jpg");
const request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) {
response.pipe(file);
});
Also in JavaScript:
- libuv nodejs
- csv export in react
- react chunk file too large
- js filter items by index
- How can I get or extract some string part from url jquery
- js select and copy on click
- Immediately-Invoked Function javascript
- how to get width of inline elements js
- vscode entenstion build
- use javascript library in react
- angularjs
- declare array in javascript
- make object move towards player p5js
- js split string on capital letter second
- empty array js
- hot to start cypress
- change dxform label angular
- javascript check if two date are ugual
- ./src/index.js Line 0: Parsing error: Cannot find module '@babel/helper-validator-identifier'
- format money javascript commas
- switch (new date().getday())
- props and state react
- jquery convert a string to an array
- how to make a deck of cards in javascript