我正在从
有人能帮忙解决吗?
这是我的配置文件:
server.js
调用config
文件。当我调用config
文件时,我收到错误消息ReferenceError:bodyparser未定义
。我不明白我的问题在哪里。有人能帮忙解决吗?
这是我的配置文件:
var
path = require('path'),
routes = require('./routes'),
exphbs = require('express-handlebars'),
express = require('express'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
morgan = require('morgan'),
methodOverride = require('method-override'),
errorHandler = require('errorhandler');
module.exports = function(app) {
app.use(morgan('dev'));
app.use(bodyParser({
uploadDir:path.join(__dirname, 'public/upload/temp')
}));
app.use(methodOverride());
app.use(cookieParser('some-secret-value-here'));
routes(app);
app.use('/public/', express.static(path.join(__dirname, '../public')));
if ('development' === app.get('env')) {
app.use(errorHandler());
}
return app;
};
server.js:
var express = require('express'),
config = require('./server/configure'),
app = express();
app
.set( "port", process.env.PORT || 3300 );
app
.set( "views", __dirname + '/views');
app = config( app );
// app
// .get('/', function( req, res ) {
// res.send( 'Hello World' );
// } );
app
.listen( app.get('port'), function () {
console.log('Server up: http://localhost:' + app.get('port'));
})
更新
module.exports = function(app) {
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser({
uploadDir:path.join(__dirname, 'public/upload/temp')
}));
app.use(methodOverride());
app.use(cookieParser('some-secret-value-here'));
routes(app);
app.use('/public/', express.static(path.join(__dirname, '../public')));
if ('development' === app.get('env')) {
app.use(errorHandler());
}
return app;
};
node_modules
中? - ddepablobodyparser
在错误中是小写的。你在哪一行得到了这个错误? - Nonemoticoner