Why isn't node's 'fs' module loading? (error: Object #<Object> has no method 'readFile')
Why isn't node's 'fs' module loading? (error: Object #<Object> has no method 'readFile')
出于某种原因,我的快速服务器没有正确加载文件系统 'fs' 模块。我正在使用 angular-fullstack yeoman 生成器。我的系统是 Windows7,node 版本 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
它是 readFile()
而不是 readfile()
(大写 F
与小写 f
)。
出于某种原因,我的快速服务器没有正确加载文件系统 'fs' 模块。我正在使用 angular-fullstack yeoman 生成器。我的系统是 Windows7,node 版本 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
它是 readFile()
而不是 readfile()
(大写 F
与小写 f
)。