public
anonymous / gist:3620800
Last active

express 3.0 socket.io + bodyparser

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
var express = require('express')
, app = express()
, format = require('util').format
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
 
app.start = app.listen = function(){
return server.listen.apply(server, arguments)
}
 
app.use(express.bodyParser());
 
app.get('/', function(req, res){
res.send('<form method="post" enctype="multipart/form-data">'
+ '<p>Title: <input type="text" name="title" /></p>'
+ '<p>Image: <input type="file" name="image" /></p>'
+ '<p><input type="submit" value="Upload" /></p>'
+ '</form>');
});
 
app.post('/', function(req, res, next){
// the uploaded file can be found as `req.files.image` and the
// title field as `req.body.title`
res.send(format('\nuploaded %s (%d Kb) to %s as %s'
, req.files.image.name
, req.files.image.size / 1024 | 0
, req.files.image.path
, req.body.title));
});
 
 
app.start(8080)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.