J
J
jtag2019-05-08 00:06:41
Node.js
jtag, 2019-05-08 00:06:41

How to send file from server and save it using browser?

How to send a file from the server and save it using a browser to the local file system?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Terentiev, 2019-05-08
@mtix

If the file is large enough, then it can be implemented using streams.

const http = require("http");
const fs = require("fs");
 
http.createServer(function(request, response){
     
    if(request.url=="/some.doc"){
        response.writeHead(200, {"Content-Type" : "application/msword"});
        fs.createReadStream("some.doc").pipe(response);
    }
    else{
        response.end("hello world!");
    }
     
}).listen(3000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question