how to create a file with no extension using createWriteStream?

1.1k Views Asked by At

so my file to create is like this ./example/myfilename with no extension, and nodejs createWriteStream apparently thinks it is a folder and throws Error: EISDIR: illegal operation on a directory. any way to work around this?

1

There are 1 best solutions below

0
On

Do you mean something similar?

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);

This pipes well my Postman posting to the file.