Skip to content

Instantly share code, notes, and snippets.

@leafsummer
Last active August 29, 2015 14:24
Show Gist options
  • Save leafsummer/16aeb58c28feeba067bb to your computer and use it in GitHub Desktop.
Save leafsummer/16aeb58c28feeba067bb to your computer and use it in GitHub Desktop.
nodejs, parse post request (simple example)
var http = require('http');
var querystring = require('querystring');
var server = http.createServer(function(req, res){
var post = '';
req.on('data', function(chunk){
post += chunk;
});
req.on('end', function(){
post = querystring.parse(post);
res.write(post.title);
res.write(post.text);
res.end();
});
}).listen(3000);
//use the express
var express = require('express');
var app = express.createServer();
app.use(express.bodyParser());
app.all('/', function(req, res){
res.send(req.body.title + req.body.text);
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment