Fs createWriteStream doesn't work with assets?


#1

I’m not so expert with fs of node.js, but I tried to do a thing like this, following the example in this module : https://www.npmjs.com/package/html-convert to convert html to gif, in async function :

 var htmlConvert = require('html-convert');
 var fs = require('fs');

 var convert = htmlConvert({
    fetchTimeout: 10000,
    renderTimeout: 3000,
    format: 'gif',
    width: 607,
    height: 403,
    phantomFlags: ['--ignolsre-ssl-errors=true'],
    maxRenders: 1000,
 });

 await fs.createReadStream('public/profilogif.html')
   .pipe(convert())
   .pipe(fs.createWriteStream("assets/profilogif.gif"));

But it threw this error

https://pastebin.com/gkPxexiV

And so I removed this part

    .pipe(fs.createWriteStream("assets/profilogif.gif"));

and the error was not thrown anymore.
So, I think that the problem is the assets folder. Any idea?


#2

Do you are trying to create the file in the default assets folder? If so, this is impossible since assets is not really a folder, it just list all your project files which are in the Glitch CDN.


#3

A file with that name already exists in the folder, but I don’t know if referencing to it with his name works(it’s name is “profilogif.gif”).


#4

If you have an assets folder locally, then try a direct rather than relative reference to the directory e.g. __dirname + '/assets/profilogif.gif' If as NikoBotDev mentioned, you’re referring to ‘assets’ in the Glitch editor, then that’s a virtual folder so you’ll create the folder locally first.


#5

So I should create a local folder, then?
Ok, I’ll try that! Thank you for your help.