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春计算机在线作业答案,东师计算机