If the nonmetal is reacting with atom of another nonmetal, then it shares electrons with the other atom in form of a covalent bond.
If the nonmetal is reacting with an atom metal, then the nonmetal gains an electron from the metal atom, it's called ionic bond.