Reputation: 11807
I am still learning node.js and trying to add connect middleware to this code:
var express = require('express')
var hbs = require('express-handlebars');
var connect = require('connect'),
path = require('path'),
hbs = require('express-handlebars');
app = express();
app.engine('handlebars', hbs(
{defaultLayout: 'main',
layoutsDir: app.get('views') + '/layouts',
partialsDir: [app.get('views') + '/partials']
}));
app.set('view engine', 'handlebars');
app.set('port', process.env.PORT || 3300);
app.set('views', __dirname + '/views');
var server = app.listen(app.get('port'), function() {
console.log('Server up: http://localhost:' + app.get('port'));
});
However the sample code on connect docs also contains:
var app = connect();
Which would confilct with what express wants. So I'm wondering how can I have both, so that I can use these middlewares:
app.use(connect.json());
app.use(connect.urlencoded());
app.use(connect.methodOverride());
app.use(connect.cookieParser('some-secret-value-here'));
I've searched but could not find up-to-date code samples about this.
Upvotes: 1
Views: 43
Reputation: 707476
A book that documents Express 3 is going to be misleading in a number of ways when using Express 4 because a lot of the functionality that one used to use Connect for is now built into Express 4. The Express JS web site is really quite good and you can pretty much see anything you want to about middleware on that site.
For example, here's a page about the built-in middleware.
Upvotes: 1