{ [Error: EISDIR: illegal operation on a directory, read] errno: -21, code: 'EISDIR', syscall: 'read' }
在 windows 上运行没问题 mac 就报这个错 百度谷歌都翻遍了。。node 初学者
|      1William911      2019-08-11 12:01:36 +08:00 via iPhone 在文件目录上读操作? | 
|      2df4VW      2019-08-11 12:19:37 +08:00 谷歌第一条 EISDIR means that the target of the operation is a directory in reality but that the expected filetype of the target is something other than a directory. | 
|  |      3wumao OP @William911 #1 是的 代码如下   然后目录文件什么的都是存在的 在 windows 上一点问题都没 const http = require('http'); const fs = require('fs'); const path = require('path'); const server = http.createServer(); server.on('request', (req, res) => { console.log(req.url); fs.readFile(path.join(__dirname, 'pages', req.url ), (err, data) => { if (err) { return console.log(err); } res.end(data); }) }); server.listen(9999, () => { console.log('http://localhost:9999/index.html 服务器已启动') }); | 
|  |      4wumao OP @df4VW #2 我单独打印了 path.join(__dirname, 'pages', req.ur ) 发现拼接得没有问题啊 | 
|  |      5wumao OP 知道什么问题了。。。  是 req.url 这个  为什么 windows 打开 127.0.0.1:9999 会直接跳转到 127.0.0.1:9999/index.html  mac 上如果打开就是 127.0.0.1:9999。。。 | 
|      6df4VW      2019-08-11 12:58:31 +08:00  1 When the path is a directory, the behavior of fs.readFile() and fs.readFileSync() is platform-specific. On macOS, Linux, and Windows, an error will be returned. On FreeBSD, a representation of the directory's contents will be returned. mac 上报错没啥问题,因为你试着读一个 directory,理论上你 windows 也应该报错,看你 windows 上有啥不同了 |