Почему не загружается модуль 'fs' узла? (ошибка: у объекта #<Object> нет метода readFile)

По какой-то причине мой экспресс-сервер неправильно загружает модуль fs файловой системы. Я использую йоменский генератор angular-fullstack. Моя система - Windows 7 с версией узла 0.10.35, версией npm 2.1.18 и последней версией angular-fullstack. Я пробовал все виды вещей, как 32-битные и 64-битные и обновлял все.

route.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 ответ

Решение

Это readFile() не readfile() (верхний регистр F против строчных f).

Другие вопросы по тегам