Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js下载多个文件_Node.js_File_Download - Fatal编程技术网

Node.js下载多个文件

Node.js下载多个文件,node.js,file,download,Node.js,File,Download,我需要从URL下载多个文件。我在档案里有他们的名单。我该怎么做?我已经做到了,但不起作用。在启动下一个wan之前,我需要等待直到最后一次下载完成。我如何才能做到这一点?在此之前,您希望从文件的回调调用下载函数。我把东西扔在一起,不要认为它很漂亮,也不要准备好;p> http-get不是一个标准节点模块,您可以通过npm-install-http-get安装它。在此之前,您需要从文件的回调调用下载函数。我把东西扔在一起,不要认为它很漂亮,也不要准备好;p> http-get不是标准的节点模块,您可

我需要从URL下载多个文件。我在档案里有他们的名单。我该怎么做?我已经做到了,但不起作用。在启动下一个wan之前,我需要等待直到最后一次下载完成。我如何才能做到这一点?

在此之前,您希望从文件的回调调用下载函数。我把东西扔在一起,不要认为它很漂亮,也不要准备好;p>
http-get
不是一个标准节点模块,您可以通过
npm-install-http-get

安装它。在此之前,您需要从文件的回调调用下载函数。我把东西扔在一起,不要认为它很漂亮,也不要准备好;p>
http-get
不是标准的节点模块,您可以通过
npm-install-http-get

安装它。您可以使用节点js中的fs(var-fs=require('fs');)读取文件

fs.readFile('<filepath>', "utf8", function (err, data) {
        if (err) throw err;
        console.log(data);
                });
fs.readFile(“”,“utf8”,函数(错误,数据){
如果(错误)抛出错误;
控制台日志(数据);
});

您可以使用节点js中的fs(var fs=require('fs');)读取文件

fs.readFile('<filepath>', "utf8", function (err, data) {
        if (err) throw err;
        console.log(data);
                });
fs.readFile(“”,“utf8”,函数(错误,数据){
如果(错误)抛出错误;
控制台日志(数据);
});

我想这就是你要找的

const fs=require('fs'))
常量https=require('https')
const downloadFolderPath='downloads'
常量URL=[
“url 1”,
“url 2”
]
const downloadFile=url=>{
返回新承诺((解决、拒绝)=>{
const splitUrl=url.split(“/”)
const filename=splitUrl[splitUrl.length-1]
const outputPath=`${downloadFolderPath}/${filename}`
const file=fs.createWriteStream(outputPath)
https.get(url,res=>{
如果(res.statusCode==200){
res.pipe(文件).on('close',resolve)
}否则{
拒绝(res.statusCode)
}
})
})
}
如果(!fs.existsSync(downloadFolderPath)){
fs.mkdirSync(下载文件夹路径)
}
让下载的文件=0
forEach(异步url=>{
等待下载文件(url)
下载的文件++
console.log(`${downloaddedfiles}/${url.length}下载`)
})

我想这就是你要找的

const fs=require('fs'))
常量https=require('https')
const downloadFolderPath='downloads'
常量URL=[
“url 1”,
“url 2”
]
const downloadFile=url=>{
返回新承诺((解决、拒绝)=>{
const splitUrl=url.split(“/”)
const filename=splitUrl[splitUrl.length-1]
const outputPath=`${downloadFolderPath}/${filename}`
const file=fs.createWriteStream(outputPath)
https.get(url,res=>{
如果(res.statusCode==200){
res.pipe(文件).on('close',resolve)
}否则{
拒绝(res.statusCode)
}
})
})
}
如果(!fs.existsSync(downloadFolderPath)){
fs.mkdirSync(下载文件夹路径)
}
让下载的文件=0
forEach(异步url=>{
等待下载文件(url)
下载的文件++
console.log(`${downloaddedfiles}/${url.length}下载`)
})

最大的问题是,如何读取文件,哪里是要下载的文件列表。请问我该怎么做?最大的问题是,如何读取文件,哪里是要下载的文件列表。请问我该怎么做?您需要从url提供的页面提取文件吗?或者您只是想下载url?是否需要从url提供的页面提取文件?或者你只是想下载网址?