如何将CSV文件直接保存到文件夹目的地?
目前我的代码在浏览器中提示保存窗口,我不希望这样。
我希望NodeJS将CSV直接保存到目标文件夹
我该怎么做?
var fs = require('fs');
var express = require('express');
csv = require('express-csv');
var request = require('request');
var cheerio = require('cheerio');
var async = require('async');
var app = express();
app.get('/scraper', function(req, res){
var offset = req.query.offset || 0;
var limit = req.query.limit || 50;
if(gCounter === 0){
getStreamerInfo(offset, limit, function(response){
console.log("FILE READY!");
res.csv(response); // this export to browser but I want to save directly to a folder
});
}
});
答案 0 :(得分:0)
如果有人正在寻找相同的答案,这就是我所做的:
var fs = require('fs');
var jsonexport = require('jsonexport');
jsonexport(response,function(err, csv){
fs.writeFile("C:/outcome/c.csv", csv, function(err) {
if(err) {}
});
});
//res.csv(response);