M
M
misc12014-10-24 14:02:53
Webkit
misc1, 2014-10-24 14:02:53

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();

As you can see, the file is being uploaded your_app.exe. How can I open the file after downloading?
Application on node-webkit 0.10.5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Zenkov, 2014-10-27
@misc1

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 question

Ask a Question

731 491 924 answers to any question