On an attempt to determine if the passed path is a folderif (await fs.stat (path) .isDirectory ()) {path += '/index.html'; }
the node throws an error: TypeError: fs.stat (...). isDirectory is not a function
Why is it outdated? nodejs.org/dist/latest-v16.x/docs/api/fs.html#statsisdirectory
Alexey Ten2021-12-15 19:32:28how do you import fs? Which version of .stat are you calling?
Grundy2021-12-16 03:59:49-
Answer # 1
Function
isDirectory
is not obsolete.In this case, the method is used incorrectly
stat
...Assuming the.
This method returns
Promise
to wait withawait
... In this caseawait fs.stat (path) .isDirectory ()
await
applies to the whole expressionfs.stat (path) .isDirectory ()
, henceisDirectory
called atPromise
... There is no such method, which is why the error occurs.To fix it, just place the parentheses:
(await fs.stat (path)). isDirectory ()
-
Answer # 2
Function
isDirectory
is not obsolete.In this case, the method is used incorrectly
stat
...Assuming the.
This method returns
Promise
to wait withawait
... In this caseawait fs.stat (path) .isDirectory ()
await
applies to the whole expressionfs.stat (path) .isDirectory ()
, henceisDirectory
called atPromise
... There is no such method, which is why the error occurs.To fix it, just place the parentheses:
(await fs.stat (path)). isDirectory ()
-
Answer # 3
Function
isDirectory
is not obsolete.In this case, the method is used incorrectly
stat
...Assuming the.
This method returns
Promise
to wait withawait
... In this caseawait fs.stat (path) .isDirectory ()
await
applies to the whole expressionfs.stat (path) .isDirectory ()
, henceisDirectory
called atPromise
... There is no such method, which is why the error occurs.To fix it, just place the parentheses:
(await fs.stat (path)). isDirectory ()
- javascript : Finding the same characters in a string
- javascript : Why am I getting sass is not a function error in gulp when using the gulp-sass module?
- javascript : How to query data with PostgreSQL in reverse order
- javascript : I want to UPDATE using placeholders in Node + MySQL
- javascript : A value different from the displayed value is UPDATEd to MySQL.
- javascript : How to partition an array from the server side
- javascript : How to run selenium webdriver on vps?
- javascript : Very long C code execution #
- javascript : Create a video conference
- javascript : How to track the addition of a new block to the page in puppeteer?
Can you read the documentation?
Alexey Ten2021-12-16 19:27:10