Home > Net >  how to save and read file from %temp% using node js?
how to save and read file from %temp% using node js?

Time:03-25

This is the code that creates a blob file and save that in folder, i want to save the screen.webm into the windows temp folder and read the files from the same folder later on

async function handleStop(e) {
    const blob = new Blob(recordedChunks, {
        type: 'video/webm'
    });

    const buffer = Buffer.from(await blob.arrayBuffer());

    const { filePath } = await dialog.showSaveDialog({
        buttonLabel: 'Save video',
        defaultPath: `vid-${Date.now()}.webm`
    });

    fs.writeFile('screen.webm', buffer, function(err){
        if(err) throw err;
        console.log(err)
    })
    if (filePath) {
        writeFile(filePath, buffer, () => console.log('video saved successfully!'));
    }

    while(recordedChunks.length>0){
        recordedChunks.pop()
    }
}

this function is broken as it will save the file in the same folder in which the js file is. and as backup i also added a user prompt so that user can save the file in the desired folder. i am usnig Electron JS to build a screen recorder.

CodePudding user response:

os.tmpdir() returns the operating system's default directory for temporary files as a string

const os = require('os');

os.tmpdir();
  • Related