F
F
FastClick2019-07-01 18:01:36
Node.js
FastClick, 2019-07-01 18:01:36

How to get file content from node.js link?

There is a file, here is a link to it: test.ru/text.txt (example), how can I get the contents of this file through node.js. The file contains a number.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
de1m, 2019-07-01
@de1m

I googled for you.
If the file is large, then take writeSteam

const http = require('http');
const fs = require('fs');

const file = fs.createWriteStream("file.jpg");
const request = http.get("http://test.ru/text.txt ", function(response) {
  response.pipe(file);
});

And if the file is small, then just into a variable
const http = require('http');
var downFile = "";

const request = http.get("http://test.ru/text.txt ", function(response) {
   downFile(response);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question