Answer the question
In order to leave comments, you need to log in
How to open a file through nodejs?
There is this code:
var http = require('http');
var fs = require('fs');
function getFile (){
var file = fs.createWriteStream("./your_app.exe");
var req = http.get("http://cdn.cdn.com/your_app.exe", function(res) {
res.pipe(file);
});
}
getFile();
your_app.exe
. How can I open the file after downloading? Answer the question
In order to leave comments, you need to log in
fs.exists('./your_app.exe', function (exists) { //проверка есть ли файл
if(exists) {
fs.readFile('./your_app.exe', function read(err, data) {
if (err) {
throw err;
}
console.log(data); // содержание файла
});
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question