为什么节点的'fs'模块没有加载? (错误:对象#<对象>没有方法'readFile')</object>

时间:2015-01-12 02:25:36

标签: node.js express fs angular-fullstack

由于某种原因,我的快递服务器没有正确加载文件系统'fs'模块。我正在使用angular-fullstack自耕农发电机。我的系统是Windows 7,节点版本为0.10.35,npm版本为2.1.18,最新版本为angular-fullstack。我尝试了各种各样的东西,比如32位和64位并更新所有内容。

routes.js(其他路线加载正常):

'use strict';

var errors = require('./components/errors');
var express = require('express');
var fs = require('fs');

module.exports = function(app) {

    app.route('/pdf/*')
        .get(function(req, res) {
            var pdfPath = app.get('appPath') + '/assets/pdf/test.pdf';
            fs.readfile(pdfPath, function(error, data) {
                res.setHeader('Content-Disposition', 'attachment; filename="test.pdf"');
                res.setHeader('Content-Type', 'application/pdf');
                res.setHeader('Content-Length', data.length);
                res.status(200).end(data, 'binary');
            });
        });

    // All undefined asset or api routes should return a 404
    app.route('/:url(api|auth|components|app|bower_components|assets)/*')
        .get(errors[404]);    

    // All other routes should redirect to the index.html
    app.route('/*')
        .get(function(req, res) {
            res.sendfile(app.get('appPath') + '/index.html');
        });
};

服务器错误:

TypeError: Object #<Object> has no method 'readfile'
    at Object.handle (C:\Projects\policy5\server\routes.js:19:7)
    at next_layer (C:\Projects\policy5\node_modules\express\lib\router\route.js:103:13)
    at Route.dispatch (C:\Projects\policy5\node_modules\express\lib\router\route.js:107:5)
    at c (C:\Projects\policy5\node_modules\express\lib\router\index.js:195:24)
    at Function.proto.process_params (C:\Projects\policy5\node_modules\express\lib\router\index.js:251:12)
    at next (C:\Projects\policy5\node_modules\express\lib\router\index.js:189:19)
    at next (C:\Projects\policy5\node_modules\express\lib\router\index.js:166:38)
    at trim_prefix (C:\Projects\policy5\node_modules\express\lib\router\index.js:228:11)
    at c (C:\Projects\policy5\node_modules\express\lib\router\index.js:198:9)
    at Function.proto.process_params (C:\Projects\policy5\node_modules\express\lib\router\index.js:251:12)
GET /pdf/test.pdf 500 2ms - 934b

1 个答案:

答案 0 :(得分:4)

readFile()而非readfile()(大写F与小写f)。