-1

form.parse() 从未调用过,当我删除 bodyparser 时,我的会话变量通过错误,如何使其工作

日志猫

不推荐使用 write(string, encoding, offset, length)。请改用 write(string[, offset[, length]][, encoding])。events.js:85 throw er; // 未处理的 'error' 事件 ^ 错误:ENOENT,打开 '/home/pitu/CODING/NODE-PROJECTS/chichat/files/a88b7a4fbd8cb31e276ef60c8e934d2d.png' at Error (native)

app.js 文件

var express = require('express'),
app = express(), 
http = require('http'), 
path = require('path'),
fs = require('fs'), 
mysql = require('mysql'),
server = http.createServer(app),
//events = require('events'),
//path = require('path'),
//url = require('url'),
//Create a new store in memory for the Express sessions
sessionStore = new express.session.MemoryStore(),
passport = require('passport'),
flash = require('connect-flash'),
useragent = require('express-useragent'),
cookieParser = express.cookieParser('hjnjnm'),

io = require('socket.io').listen(server);

// configuration ===============================================================
// connect to our database

require('./config/passport')(passport); // pass passport for configuration

app.configure(function() {

// set up our express application
app.use(express.logger('dev')); // log every request to the console
app.use(cookieParser); // read cookies (needed for auth)
app.use(useragent.express());
app.use(express.methodOverride());
app.use(express.bodyParser({keepExtensions:true,uploadDir:path.join(__dirname,'/files')}));

app.set('view engine', 'ejs'); // set up ejs for templating

// required for passport
app.use(express.session({store: sessionStore,key: 'myuser.sid',cookie: { secure: false,maxAge:3600000}} )); // session secret1

app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(express.static(path.join(__dirname, 'public')));

app.all('*', function(req, res, next) 
{
    res.header("Access-Control-Allow-Origin", "*");
    res.set('Access-Control-Allow-Methods', 'GET, POST');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});
});
require('./app/socket/mainSocket.js')(app,io,sessionStore,cookieParser);
// routes ======================================================================
require('./app/controller.js')(app, passport,io); // load our routes and pass in our app and fully configured passport
// launch ======================================================================
server.listen(8080);

我应该使用什么,bodyparser 还是强大的,我想将大文件上传到服务器,哪一个将以最小的开销满足我的需要。任何帮助将不胜感激,谢谢

4

1 回答 1

0

[1]:https ://stackoverflow.com/a/25016730/2254638 它解决了我的问题,快乐编码,:)

于 2014-08-06T04:41:47.040 回答