DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Integrating Node.js Applications With MCP Servers
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Trending

  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines
  • Spring AI Advisors: Chat Memory, Token Tracking, and Message Logging
  • MuleSoft IDP: Enhancing Efficiency and Accuracy in Data Extraction
  • Feature Flag Debt: Performance Impact in Enterprise Applications
  1. DZone
  2. Coding
  3. JavaScript
  4. GET/POST Parameters in Node.js

GET/POST Parameters in Node.js

We look at how to write GET and POST requests into tyour Node.js-based application. It's so easy you won't believe it!

By 
Snippets Manager user avatar
Snippets Manager
·
Jun. 28, 11 · Code Snippet
Likes (1)
Comment
Save
Tweet
Share
62.1K Views

Join the DZone community and get the full member experience.

Join For Free

GET/POST parameters in Node.js are pretty simple. Only 5 lines of code to insert into your project.

var sys = require ('sys'),
url = require('url'),
http = require('http'),
qs = require('querystring');

http.createServer(function (req, res) {




    if(req.method=='POST') {
            var body='';
            req.on('data', function (data) {
                body +=data;
            });
            req.on('end',function(){

                var POST =  qs.parse(body);
                console.log(POST);
            });
    }
    else if(req.method=='GET') {
        var url_parts = url.parse(req.url,true);
        console.log(url_parts.query);
    }


}).listen(1337, "127.0.0.1");
Node.js

Opinions expressed by DZone contributors are their own.

Related

  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • Integrating Node.js Applications With MCP Servers
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook