我也不说啥了,直接上代码吧!
var express = require('express'),
//session = require('express-session'),
mongoose = require('mongoose'),
router = require('./lib/router'),
bodyParser = require('body-parser'),
multer = require('multer'),
User = require('./lib/models/user'),
app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // for parsing application/json
app.use(multer);
app.use(express.static(__dirname + '/'));
//app.use(bodyParser.json());
mongoose.connect('mongodb://localhost:27017/tfdb');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.on("open", function () {
console.log("------数据库连接成功!------");
});
router(app);
//User.create({uid:123,name:'test','phone':'12313',password:'12312321'},function (err,data) {
// if(err)
// console.log(err);
//
//
//});
console.log('you have logged in successfully!');
app.listen(5000);
求大神解答
這樣寫會讓multer把所有請求當做文件上傳進行攔截,所以瀏覽器看不到回應
正確用法是綁定到特定請求,如下