The nonlinear Schrödinger equation with a potential