Last active
August 29, 2015 14:24
-
-
Save leafsummer/16aeb58c28feeba067bb to your computer and use it in GitHub Desktop.
nodejs, parse post request (simple example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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