質問

var express = require('express'),
    routes = require('./routes'),
    http = require('http'),
    path = require('path'),
    fs = require('fs');

var app = express();

app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(express.json());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', routes.index);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

I'm getting the error Most middleware (like json) is no longer bundled with....
I've npm installed connect in the same folder.
But how do i use it?

I couldn't find any combined tutorial on connect & express, they either talk about connect or express.

役に立ちましたか?

解決

Quoting from the Express.js's middleware documentation,

As of 4.x, Express no longer depends on Connect. All of Express' previously included middleware are now in separate repos. Please view the list of middleware. The only included middleware is now express.static().

So, to use json middleware, you need to include the body-parser in the package.json and then use like this

var bodyParser = require('body-parser');
app.use(bodyParser.json());
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top