NodeJS promise recursive function meets condition and stops executing but does not return

I have made a recursive function in NodeJS which is in a promise. It is supposed to recursively query a server, and it has two conditions. If it runs out of the max amount of servers, it will return an error and quit. This part works fine. The second part is if it gets a response which contains “true” then it will have succeeded and should exit and return the response. The exting part works fine and it stops as soon as it gets a response with “true” but it does not return it.

Here is my code, I have removed the parts where I set the tensordock variables to save space.

function getPorts(getPortsInputTensordockServer) {
  return new Promise((resolve, reject) => {
    try {
      request(getPortsInputTensordockServer, (error, response, getPortsResponseBody) => {
        getPortsResponseBody = JSON.stringify(getPortsResponseBody)
        getPortsResponseBody = getPortsResponseBody.split("[")
        getPortsResponseBody = getPortsResponseBody[1]
        getPortsResponseBody = getPortsResponseBody.split("]")
        getPortsResponseBody = getPortsResponseBody[0]
        getPortsResponseBody = getPortsResponseBody.split(",")
        return resolve(getPortsResponseBody)
      })
    } catch (err) {
      reject(err)
    }
  })
}

function createVM(n, createVMResponseBody) {
  return new Promise((resolve, reject) => {
    (async () => {
        try {
            if (createVMResponseBody.includes("true") === true) {
                return resolve(createVMResponseBody)
              }
              if (n === 21) {
                return resolve("oh no! no more servers")
              }
              var tensordockServer = eval("tensordockServer" + n)
              var tensordockServerName = tensordockServerMap.get("tensordockServerName" + n)
              var getPortsResult = await getPorts(tensordockServer)
              
              var createVMOptions = {
                'method': 'POST',
                'url': 'https://marketplace.tensordock.com/api/v0/client/deploy/single',
                'headers': {
                  'Content-Type': 'application/x-www-form-urlencoded'
                },
                form: {
                  'api_key': 'xxxx',
                  'api_token': 'xxxx',
                  'password': 'superC0mplexPassword',
                  'name': 'My NVIDIA RTX A4000 Server',
                  'gpu_count': '1',
                  'gpu_model': 'rtxa4000-pcie-16gb',
                  'vcpus': '4',
                  'ram': '8',
                  'external_ports': `{${getPortsResult[0]}, ${getPortsResult[1]}}`,
                  'internal_ports': '{22, 8888}',
                  'hostnode': tensordockServerName,
                  'storage': '150',
                  'operating_system': 'Windows 10'
                }
              };
              createVMResponseBody = await createVMRequest(createVMOptions)
              createVM(n + 1, createVMResponseBody)
        } catch (err) {
            return reject(err)
        }
    })()
  })
}

function createVMRequest(createVMRequestInput) {
  return new Promise((resolve, reject) => {
    try {
      request(createVMRequestInput, (error, response, createVMRequestBody) => {
        createVMRequestBody = JSON.stringify(createVMRequestBody)
        resolve(createVMRequestBody)
      })
    } catch (err) {
      reject(err)
    }
  })
}

async function testCall() {
    const result = await createVM(1, "test")
    console.log(`The result is ${result}`)
}

testCall()

I also tried changing the condition to if it includes “test” and that works fine.