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?
just mention:
here, you need to mention function(){} as this is a callback() to write text in asynchronous manner.
Using writeFileSync will make an synchronous call
You need to include a callback function for the Asynchronous method (
writeFile
in your case).For example
where
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.
I prefer the following two methods, myself.
1:
2:
I got the same warning
and had the same problem of not knowing which part of my code was causing it. So I looked at code I had recently modified and saw this statement-suspect:
Problem was the cb (= 'callback') and the encoding arguments are in wrong order. I got rid of the warning simply by changing the above to:
But the problem really is with the ERRONEOUS warning-message. I WAS passing in a callback-argument but just one which was not a Function but a String. So if the warning had said
... it would have been obvious what was happening. Of course a line-number in the warning would be nice as well.
So the point is I was NOT calling writeFile() without a callback-argument, which is deprecated. I was calling writeFile() WITH A WRONG TYPE OF ARGUMENT. That should be an ERROR, not a warning.
You can use either the
--trace-deprecation
or--throw-deprecation
options.For example:
or:
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.this is because you have not catch error by using err callback use like below in your code