A numerical solver for nonlinear Schrödinger equations