I am trying to create a helper function to create some token and use it in other functions. In the below functions: I intend to return the token and then print it. But it is printing before completing the function and hence there is not output. Not sure how to make it synchronous such that it will always finish the function before printing the output.
var response=""
function post_request(headers=build_request_headers(), request=build_request_object()){
api = supertest(config.url+":"+ config.port)
api.post(api_path.in_requests)
.set(build_request_headers())
.send(request)
.then((res) => {
response=res
})
return response
}
console.log(post_request())