There is a way to apply for a resident visa from outside of the United States. This process is called consular processing and can be done through a U.S. consulate or embassy overseas. This process is one of the two ways people can apply for family-based immigration.
To be eligible for consular processing, a family member that is a U.S. citizen must petition on your behalf. Moreover, the person who is being sponsored must be an immediate family member of the sponsor or fall under the family preference categories. The purpose of form I-130 is to establish evidence that the individual is eligible for a green card.