2 var express = require('express');
3 var formidable = require('formidable');
4 var util = require('util');
5 var fs = require('fs');
7 var uploadDir = __dirname + '../static/uploads';
8 var documentRoot = __dirname + '../static';
11 app.post('/upload', function (req, res) {
12 var form = new formidable.IncomingForm();
13 form.uploadDir = uploadDir;
14 form.keepExtensions = true;
15 form.parse(req, function(err, fields, files) {
16 res.writeHead(200, {'content-type': 'text/plain'});
17 res.write('received upload:\n\n');
18 res.end(util.inspect({fields: fields, files: files}));
19 fs.rename(files.upload.path,
20 uploadDir + '/' + files.upload.name, function(err) {});
23 app.use(express.static(documentRoot));
24 app.use(express.directory(documentRoot));
25 app.use(express.methodOverride());