Search code examples
javascriptnode.jsnodesnode-modules

NodeJs : fs.appendFileSync does not accept a number type in data argument node v14


Version: 14.1.0 Platform: Windows 10 Subsystem: none

> error: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be
> of type string or an instance of Buffer, TypedArray, or DataView.
> Received type number (7) this is the code:
const fs = require('fs')

fs.writeFileSync('notes.txt', 'NODEJS')


fs.appendFileSync('notes.txt', 7 )

I expected to get a file with: NODEJS7 I got : NODEJS

THIS WAS WORKING IN THE PREVIOUS VERSIONS CORRECTLY!!!!!!


Solution

  • I think the fs.appendFileSync does not accept number type anymore.

    you could pass it as a template string if you have a variable, or you could use the to.String() method.