javascript Node.js - fs.stat throws ENOENT 操作成功完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7681407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:55:30  来源:igfitidea点击:

Node.js - fs.stat throws ENOENT The operation completed successfully

javascriptnode.js

提问by RHH

I'm trying to follow episode 3 of nodetuts.com. Also, I'm using the newest (unstable) version of node - node.exe, version 0.5.2. Here is my code, I've been beating my head against a wall with this error practically all day. Is it just a windows thing?

我正在尝试关注 nodetuts.com 的第 3 集。另外,我使用的是最新(不稳定)版本的节点 - node.exe,版本 0.5.2。这是我的代码,我几乎整天都在用这个错误把头撞在墙上。它只是一个窗口的东西吗?

var http = require('http');
var fs = require('fs');

var file_path = __dirname + '\me.jpg';
console.log('serving: '+file_path);
fs.stat(file_path, function(err, stat){

    if (err) throw err;

    http.createServer(function(request,response){

        response.writeHead(200, {
        'Content-Type':'image/jpeg'
        });

        fs.readFile(file_path, function(err, file_content){

            response.write(file_content);
            response.end();
        });

    }).listen(8000);
})

Thank you!

谢谢!

回答by Tower

The 0.5.x is buggy on Windows. You can do

0.5.x 在 Windows 上有问题。你可以做

fs.readFile(__dirname + '/file.txt', callback);

I believe 0.6 will fix these problems. :)

我相信 0.6 会解决这些问题。:)

回答by dresende

You should avoid using node v0.5.x for now as it's considered unstable. Use v0.4.x. If you used the git to grab node, do this:

您现在应该避免使用 node v0.5.x,因为它被认为是不稳定的。使用v0.4.x。如果您使用 git 来抓取节点,请执行以下操作:

cd /path/to/your/local/node/git
git checkout v0.4.12
make && sudo make install