I'm currently doing an exercise in learnyounode and I can't quite figure out why this version of my code isn't executing correctly.
1 'use strict';
2
3 const fs = require('fs');
4
5
6
7 fs.readdir(process.argv[2], 'utf8', callback);
8
9 var callback = function (err, files) {
10 let ext = process.argv[3];
11 files.forEach((val, idx) => {
12 if (val.split('.')[1] == ext){
13 console.log(val);
14 }
15 });
16 };
If I simply call fs.readdir(...) at the end, it executes so I know it must be an asynchronous / function closure sort of issue that I'm not understanding. Could someone explain why my code above throws an error saying (node:23729) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated. ?
Thanks!