A near field scanning optical microscope (NSOM) includes a cantilever which is aligned generally parallel to the surface of a sample. An optical waveguide extends along the cantilever to a tip which protrudes downward from the cantilever. A small aperture at the apex of the tip allows light radiation flowing through the waveguide to be directed toward the sample. The cantilever is vibrated, and variations in its resonant frequency are detected and delivered to a feedback control system to maintain a constant separation between the tip and the sample. The NSOM can also be operated as an atomic force microscope in either a contact or non-contact mode.