The transverse vibration of a nanobeam subject to initial axial compressive forces based on nonlocal elasticity theory is investigated. The effects of a small nanoscale parameter at molecular level unavailable in classical mechanics theory are presented and analyzed. Explicit solutions for natural frequency, vibration mode shapes are derived through two different methods: separation of variables and multiple scales. The respective numerical solutions are in close agreement. Validity of the models and approaches presented in the work are verified. Unlike the previous studies for a nonlocal nanostructure, this paper adopts the effective nonlocal bending moment instead of the pure traditional nonlocal bending moment. The analysis yields an infinite-order differential equation of motion which governs the vibrational behaviors. For practical analysis and as examples, an eight-order governing differential equation of motion is solved and the results are discussed. The paper presents a complete nonlocal nanobeam model and the results may be helpful for the application and design of various nano-electro-mechanical devices, e.g. nano-drivers, nano-oscillators, nano-sensors, etc., where a nanobeam acts as a basic element.