nodejs 有人遇到这个报错吗 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wumao

nodejs 有人遇到这个报错吗

  •  1
     
  •   wumao 2019 年 8 月 11 日 9377 次点击
    这是一个创建于 2450 天前的主题,其中的信息可能已经有所发展或是发生改变。

    { [Error: EISDIR: illegal operation on a directory, read] errno: -21, code: 'EISDIR', syscall: 'read' }

    在 windows 上运行没问题 mac 就报这个错 百度谷歌都翻遍了。。node 初学者

    William911
        1
    William911  
       2019 年 8 月 11 日 via iPhone
    在文件目录上读操作?
    df4VW
        2
    df4VW  
       2019 年 8 月 11 日
    谷歌第一条

    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.
    wumao
        3
    wumao  
    OP
       2019 年 8 月 11 日
    @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 服务器已启动')
    });
    wumao
        4
    wumao  
    OP
       2019 年 8 月 11 日
    @df4VW #2 我单独打印了 path.join(__dirname, 'pages', req.ur ) 发现拼接得没有问题啊
    wumao
        5
    wumao  
    OP
       2019 年 8 月 11 日
    知道什么问题了。。。 是 req.url 这个 为什么 windows 打开 127.0.0.1:9999 会直接跳转到 127.0.0.1:9999/index.html mac 上如果打开就是 127.0.0.1:9999。。。
    df4VW
        6
    df4VW  
       2019 年 8 月 11 日   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 上有啥不同了
    wumao
        7
    wumao  
    OP
       2019 年 8 月 11 日
    @df4VW #6 老哥 知道什么问题了。。。 是 req.url 这个 为什么 windows 打开 127.0.0.1:9999 会直接跳转到 127.0.0.1:9999/index.html mac 上如果打开就是 127.0.0.1:9999。。。所以路径不对 直接报错了。。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2684 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 40ms UTC 04:05 PVG 12:05 LAX 21:05 JFK 00:05
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86