can i measure output currant on an output pin

if it is a circuit requiring more than 40ma can i measure current through a mosfet or transistor?