How to download a file with Node.js (without using third-party libraries)?

后端 未结 28 1284
逝去的感伤
逝去的感伤 2020-11-22 03:37

How do I download a file with Node.js without using third-party libraries?

I don\'t need anything special. I only want to download a file from a giv

28条回答
  •  醉酒成梦
    2020-11-22 03:57

    I suggest you to use res.download same as follow:

    app.get('/download', function(req, res){
      const file = `${__dirname}/folder/abc.csv`;
      res.download(file); // Set disposition and send it.
    });
    

提交回复
热议问题