pirple / The-NodeJS-Master-Class

Code samples for the Node.js Master Class
1.32k stars 1.21k forks source link

fs.truncate with a descriptor is deprecated. #3

Closed ghost closed 6 years ago

ghost commented 6 years ago

In section three, we create the update functionality and are instructed to use fs.truncate but I received a warning from node:

(node:29626) [DEP0081] DeprecationWarning: Using fs.truncate with a file descriptor is deprecated. Please use fs.ftruncate with a file descriptor instead.

lokyi commented 6 years ago

Looks like you would get this error if you are using node v10 while @pirple-author is targeting Node v8.

Using fs.truncate with a file descriptor will actually call fs.ftruncate, according to the doc

Maybe it is more appropriate to use fs.ftruncate in production, but for demonstration purposes, using truncate is more intuitive?