Misconception "Calling an asynchronous function without a callback is out of date" warning

NodeJS gives me a warning

(node: 32600) [DEP0013] Deprecated warning: calling an asynchronous function without a callback is deprecated.

when i run this test:

describe('whatever', () => {
  it('test simple', async () => {
    const dir = './build/fileTests';

    if (fs.existsSync(dir)) {
      console.log(`deleting ${dir}`);
      await fs.rmdir(dir);
    }
  });
});

Well, I would almost agree that using asynchronous functions without a callback is bad (since only inside cb you can know exactly what happened, go on, etc.

... if it were not for my intentional use of ES7 async/await , because they do it synchronously, so I can work with what I get ... (in this special case, I could avoid rmdirSync , but that's not my point. ..)

so my question is: how can I get rid of such warnings?

- , async/await... - , const r = ... ...

+4
1

fs.rmdir , swag. , node.js promisify util core module

. async fs,

const util = require("util");
const fs = require("fs");
const removeDir = util.promisify(fs.rmdir);

const rmDir = async () => {
   try {
      await removeDir("directory_name");
   } catch(ex) {
      console.error(ex)
   }
}

,

: uti.promisify(fs.rmdir), @bergi

: try .. catch block

+6

Source: https://habr.com/ru/post/1687547/


All Articles