【问题标题】:how to create a file with no extension using createWriteStream?如何使用 createWriteStream 创建没有扩展名的文件?
【发布时间】:2019-08-08 11:46:19
【问题描述】:

所以我要创建的文件是这样的./example/myfilename,没有扩展名,而nodejs createWriteStream 显然认为它是一个文件夹并抛出Error: EISDIR: illegal operation on a directory。有什么办法可以解决这个问题?

【问题讨论】:

  • 无法重现。 fs.createWriteStream('/tmp/myfilename') 在我的 Linux 桌面上运行良好。

标签: node.js createwritestream


【解决方案1】:

你的意思是类似的吗?

var http = require('http');
var fs = require('fs');

http.createServer(function(req, res) {

  let writeStream = fs.createWriteStream('./temp/output', {"flags":"a"});

  // This pipes the POST data to the file
  req.pipe(writeStream);

  req.on('end', function () {
    res.writeHead(200, {"content-type":"text/html"});
    res.end('All went ok.');
  });

  writeStream.on('error', function (err) {
    console.log(err);
  });
}).listen(8080);

这很好地将我的邮递员发布到文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    相关资源
    最近更新 更多