Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeprecationWarning: Calling an asynchronous function without callback is deprecated. - how to find where the "function:" is?

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?

like image 960
AGamePlayer Avatar asked Dec 17 '16 05:12

AGamePlayer


People also ask

Is callback and asynchronous equivalent for a function?

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.

Does taking a callback make a function asynchronous?

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.

Is callback function synchronous or asynchronous?

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.

What is the purpose of a callback in an asynchronous function?

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.


2 Answers

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.

like image 159
cartant Avatar answered Sep 18 '22 19:09

cartant


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.

like image 34
NewDev2017 Avatar answered Sep 21 '22 19:09

NewDev2017