Node: fs module unable to write data to file

Created on 29 Dec 2017  路  6Comments  路  Source: nodejs/node

  • v9.3.0:
  • Linux 4.14.8-1-ARCH:
  • fs:
// hello.js

fs = require('fs');
fs.writeFile('hello.txt', 'Hello, World!', err => {
    if (err)
        console.log(err);

    console.log('success');
});

The output of $ node hello.js is success, as expected. The hello.txt file is created, but is blank on checking the contents.

I've tried every variation of this code I could think of, using append and write methods, *Sync() versions of the methods, and writing to the file using filestreams. None have worked.

fs

Most helpful comment

I have run the code and it created the file successfully whit "Hello, World! " inside, maybe the problem is another thing

All 6 comments

Hi @monodokimes!

Thanks for the bug report.

Does the problem still occur if you remove hello.txt before running the script?

If yes, can you upload and share the output of running strace node hello.js somewhere (you might need to install the strace utility first on your system)?

The problem occurs consistently trying to create and write to any file, whether the file exists before the call or not.

Output of strace node hello.js: https://pastebin.com/F2yUS3zD

@monodokimes Can you also post the output of strace -f node hello.js? Without -f it only traces the main thread.

I have run the code and it created the file successfully whit "Hello, World! " inside, maybe the problem is another thing

@bacriom I'm pretty sure it's a platform problem, I would find it hard to believe fs is this fundamentally broken everywhere.

No follow-up, closing.

Was this page helpful?
0 / 5 - 0 ratings