N
N
nezzard2017-01-11 18:58:01
Node.js
nezzard, 2017-01-11 18:58:01

Does fs.writeFileSync have a callback?

Good afternoon, I need a callback for fs.writeFileSync
But I get an error if I call something like this

fs.writeFileSync("/tmp/img/"+convert(artist)+".png", body, 'binary', function(err) {
                      if(err){
                        console.log('err');
                      }
})

If you do this with writeFile, then everything works fine, but this option does not suit me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2017-01-11
@werty1001

try {
  fs.writeFileSync( mypath, mydata );
} catch ( e ) {
  console.log( 'Error' );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question