formidable.js 559 B

1234567891011121314151617
  1. var formidable = require('formidable'),
  2. http = require('http'),
  3. util = require('util');
  4. var port = process.argv[2] || 8888;
  5. http.createServer(function(req, res) {
  6. var form = new formidable.IncomingForm();
  7. form.parse(req, function(err, fields, files) {
  8. res.writeHead(200, {'content-type': 'text/plain'});
  9. res.write('received upload:\n\n');
  10. console.log(util.inspect({fields: fields, files: files}))
  11. res.end(util.inspect({fields: fields, files: files}));
  12. });
  13. }).listen(port);
  14. console.log('HTTP server listening on port ' + port);