<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: reachmmadhu</title>
    <description>The latest articles on DEV Community by reachmmadhu (@reachmmadhu).</description>
    <link>https://dev.to/reachmmadhu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F648117%2Fa9fa5461-fc47-4959-bb81-190a11eee6fb.png</url>
      <title>DEV Community: reachmmadhu</title>
      <link>https://dev.to/reachmmadhu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reachmmadhu"/>
    <language>en</language>
    <item>
      <title>Nodejs, How do I wait until the previous post request is completed.</title>
      <dc:creator>reachmmadhu</dc:creator>
      <pubDate>Sat, 12 Jun 2021 06:34:11 +0000</pubDate>
      <link>https://dev.to/reachmmadhu/nodejs-how-do-i-wait-until-the-previous-post-request-is-completed-1i0g</link>
      <guid>https://dev.to/reachmmadhu/nodejs-how-do-i-wait-until-the-previous-post-request-is-completed-1i0g</guid>
      <description>&lt;p&gt;How can i make to wait until I get response from the below snippet before moving with the next line. In Nodejs it is executing further lines of code or functions. Here i am calling GetAccessToken() First and then fn1(). IN this case GetAccessToken is not waiting for the response and get executed fn1() later getting the Token Value. Any help on this would be great.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var log = {
    GetAccessToken: function() 
    {
        var https = require('follow-redirects').https;

        var qs = require('querystring');

        var options = {
        'method': 'POST',
        'hostname': 'corpqa.sts.xxxx.com',
        'path': '/adfs/oauth2/token',
        'headers': {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        'maxRedirects': 20
        };

        var req =  https.request(options, function (res) {
            var chunks = [];

            res.on("data", function (chunk) {
                chunks.push(chunk);   
            });

             res.on("end",  function (chunk) {
                var body = Buffer.concat(chunks);

                console.log(body.toString());        
            });

            res.on("error", function (error) {
                console.error(error);  
            });
            });

        var postData = qs.stringify({
        'grant_type': 'client_credentials',
        'client_id': '0asda7b-a7dc-8582-6b0f-02f6d704d4b0',
        'client_secret': 'm2deXPEvx2sdlRFZtsjkKR_HfDvW5MuDp4',
        'resource': 'urn:webservices:resource:api_webservices:dev',
        'redirect_uri': 'https://xgtwdev.xxxx.com/7777/ssswebsvc/sssdocumentumservicesWeb',        
        'code': '',
        'nonce': 'Nonce Change for each Transaction',
        'state': 'State Change for each Transaction'
        });

        req.write(postData);

        req.end();

    },
    UploadFile:function()
    {
        console.log("Execute UploadFile");
    }
}

module.exports = log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
