I recently updated my node to 7.2.1 and noticed that there is a warning coming:
(node:4346) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
What is this 4346
for? I only have 2000 lines in the js file, so it can't be a line-number. Where can I find the code?
Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All the APIs of Node are written in such a way that they support callbacks.
The function that takes another function as an argument is called a higher-order function. According to this definition, any function can become a callback function if it is passed as an argument. Callbacks are not asynchronous by nature, but can be used for asynchronous purposes.
The callback is a function that's accepted as an argument and executed by another function (the higher-order function). There are 2 kinds of callback functions: synchronous and asynchronous. The synchronous callbacks are executed at the same time as the higher-order function that uses the callback.
Asynchronous callbacks are functions passed to another function that starts executing code in the background. Typically, when the code in the background finishes, the async callback function is called as a way of notifying and passing on data to the callback function that the background task is finished.
You can use either the --trace-deprecation
or --throw-deprecation
options.
For example:
node --trace-deprecation app.js
or:
node --throw-deprecation app.js
The first option will log a stack trace and the second will throw an error (which, if not caught, will also log a stack trace).
Also, 4346
is most likely the process ID.
You need to include a callback function for the Asynchronous method (writeFile
in your case).
For example
var fs = require('fs'); fs.writeFile('writeMe.txt',data,'utf8',(error)=>{ // your code goes here });
where
(error) => { });
is the callback function.
From Version: v7.0.0
The callback parameter is no longer optional. Not passing it will emit a deprecation warning.
Please refer: https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With