Posted By

saturngod on 06/28/11


Tagged

get


Versions (?)

GET / POST parameter in Node.js


 / Published in: JavaScript
 

  1. var sys = require ('sys'),
  2. url = require('url'),
  3. http = require('http'),
  4. qs = require('querystring');
  5.  
  6. http.createServer(function (req, res) {
  7.  
  8.  
  9.  
  10.  
  11. if(req.method=='POST') {
  12. var body='';
  13. req.on('data', function (data) {
  14. body +=data;
  15. });
  16. req.on('end',function(){
  17.  
  18. var POST = qs.parse(body);
  19. console.log(POST);
  20. });
  21. }
  22. else if(req.method=='GET') {
  23. var url_parts = url.parse(req.url,true);
  24. console.log(url_parts.query);
  25. }
  26.  
  27.  
  28. }).listen(1337, "127.0.0.1");

Report this snippet  

You need to login to post a comment.