I can't write on /tmp/file.txt (read-only file system)

Hi Guys, I’m trying to write on /tmp/file.txt I don’t know the reason why, it keeps giving me an EROFS: read-only file system Error

Hi @9orsaan

Why are you trying to write to /tmp? Is this during build, or in a function?

I’m trying to write through a function, This the code snippet:

router.post('/data',(req,res) =>{
    const content = req.body

    if(content != null){
        fs.writeFileSync("./tmp/file.txt",content,{encoding:'utf8',flag:'w'})
        res.send("Data Updated!")
    }else{
        res.sendStatus(403);
    }
});

Context for others:

@9orsaan,

The problem is, you’re using ./tmp which is incorrect. The correct version is: /tmp.

2 Likes

@hrishikesh Thank You I’ll Try It

1 Like