javascript - Node Js CreateWriteStream不会写入目录

标签 javascript node.js request fs

我似乎无法使 fs.createFileStream 写入目录。

var filePath = fs.createWriteStream('./path/to/store/file.png');            
var rem = rquest('http://domain.com/img/img.png');

rem.on('data', function(chunk) {
    filePath.write(chunk);
    response.write(chunk);
});

rem.on('response', function(res){
    response.writeHead(200, res.headers);
});

rem.on('end', function() {
    response.end();
});

如果我将文件名传递到 CreateWritStream 中,它就可以正常工作

var filePath = fs.createWriteStream('file.png');

我做错了什么?

最佳答案

正如@thefourtheye 在评论部分所述

It will not create the directories on its own. All the directories in the path should exist and should be writable.

是正确的解决方案。

关于javascript - Node Js CreateWriteStream不会写入目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30617559/

相关文章:

javascript - 制作一个函数,从可被 3 整除的数组中提取所有数字

javascript - 谷歌登录没有反应

javascript - Selenium 通过 Node.js 和 webdriverIO : timeout without effect

Facebook 批量请求

ruby-on-rails - 如何在 Rails(瘦服务器或 webrick 服务器)中设置请求超时

javascript - 更改窗口打开位置

javascript - qtip2 气球和 php 表 : different balloon content for each row?

node.js - 缺少 Node.js 的目录

node.js - 无法解析 sequelize 包

javascript - 请求 promise 返回未定义但存在