How to make the functions in the loop execute synchronously in node.js

  node.js, question

Recently, the school began to select courses. I am writing a brush machine to practice my hands. The last step is to continuously request the server to select classes for post. I intend to execute this post operation in a dead loop and control when to jump out of the loop through a callback function. I would like to ask how to make the functions in the loop body execute synchronously and sequentially in node.js. My code is roughly as follows:

while (1)
 bracket
 request.post({
 url: url,
 form:
 bracket
 CourseId: "123456" // Course Information
 },
 jar: cookieJar
 }, function (err, res, body)
 bracket
 console.log(res.statusCode);
 If (body))//successfully selected or no margin left
 bracket
 ... jump out of the loop
 bracket
 });
 bracket

I hope to be able to execute each post operation in turn and output the statusCode before executing the next post.
Grateful

Using recursion:

function postData(){
 request.post({
 url: url,
 form:
 bracket
 CourseId: "123456" // Course Information
 },
 jar: cookieJar
 }, function (err, res, body)
 bracket
 console.log(res.statusCode);
 If (body))//successfully selected or no margin left
 bracket
 return;
 bracket
 else{
 postData();
 bracket
 });
 bracket
 
 postData();