I have an upcoming flight leaving Newark Terminal B around 2am. How late are the security lines/TSA open?
The simple answer for all airports and all flights, is that presuming you arrive in time to catch your flight, then TSA will be open and available.
Exact hours for TSA do vary - some terminals in some airports they are open 24x7, whilst for most airports (including major airports) they are not. For those that are not open 24x7, the times vary depending on flight schedules. If there are periods overnight where there are no flights due to depart, then TSA will often be closed during those hours - even if the airport itself remains open.
In some cases the airport will list the hours on their website (eg, here are the times for San Francisco International Airport), however Newark Liberty does not appear to list such times.
Note that where this can become an issue is if your flight is delayed. There is no guarantee that TSA will remain open. Thus if your 2am flight is delayed until 4am, you should still plan on getting to the airport as if the departure was at 2am, otherwise you may find that it is not possible to get to your gate!