node.js报错“Error: EPERM: operation not permitted, stat ‘C:\Recovery‘“
生活随笔
收集整理的這篇文章主要介紹了
node.js报错“Error: EPERM: operation not permitted, stat ‘C:\Recovery‘“
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
異常
node:internal/fs/utils:344throw err;^Error: EPERM: operation not permitted, stat 'C:\Recovery'at Object.statSync (node:fs:1536:3)at D:\NodeJs\node-demo\demo\world.js:7:24at FSReqCallback.oncomplete (node:fs:188:23) {errno: -4048,syscall: 'stat',code: 'EPERM',path: 'C:\\Recovery' }Node.js v17.1.0錯誤代碼
var fs = require('fs');var rootPath = 'C:\\'; fs.readdir(rootPath, function (err, files) {for (var i = 0; i < files.length; i++) {var p = rootPath + files[i];var stats = fs.statSync(p);console.log(rootPath + '是否是目錄:' + stats.isDirectory())} });原因
其實代碼沒有任何問題,看錯誤提示Error: EPERM: operation not permitted, stat 'C:\Recovery'是權限問題,因為要統計的是C盤即系統盤的信息,所以需要管理員權限才能調用。
解決
以管理員身份打開命令提示符
跳轉到待執行的文件的目錄下,然后使用node命令執行js文件:
總結
以上是生活随笔為你收集整理的node.js报错“Error: EPERM: operation not permitted, stat ‘C:\Recovery‘“的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bootstrap表格样式大全
- 下一篇: 东师18春计算机在线作业答案,东师计算机