Node.js - fs.stat抛出ENOENT操作成功完成 [英] Node.js - fs.stat throws ENOENT The operation completed successfully

查看:261
本文介绍了Node.js - fs.stat抛出ENOENT操作成功完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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);
})

谢谢!

推荐答案

0.5.x是Windows上的错误。你可以做

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

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

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

I believe 0.6 will fix these problems. :)

这篇关于Node.js - fs.stat抛出ENOENT操作成功完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆