In doubles you must serve diagonally, but in singles you can serve in any direction.
The rules for service are in Section 2.06 of the ITTF Handbook:
2.06 THE SERVICE
2.06.01 Service shall start with the ball resting freely on the open palm of the server's stationary free hand.
2.06.02 The server shall then project the ball near vertically upwards, without imparting spin, so that it rises at least 16cm after leaving the palm of the free hand and then falls without touching anything before being struck.
2.06.03 As the ball is falling the server shall strike it so that it touches first his or her court and then, after passing over or around the net assembly, touches directly the receiver's court; in doubles, the ball shall touch successively the right half court of server and receiver.
2.06.04 From the start of service until it is struck, the ball shall be above the level of the playing surface and behind the server's end line, and it shall not be hidden from the receiver by the server or his or her doubles partner or by anything they wear or carry.
2.06.05 As soon as the ball has been projected, the server’s free arm and hand shall be removed from the space between the ball and the net.
The space between the ball and the net is defined by the ball, the net and its indefinite upward extension.
2.06.06 It is the responsibility of the player to serve so that the umpire or the assistant umpire can be satisfied that he or she complies with the requirements of the Laws, and either may decide that a service is incorrect.
2.06.06.01 If either the umpire or the assistant umpire is not sure about the legality of a service he or she may, on the first occasion in a match, interrupt play and warn the server; but any subsequent service by that player or his or her doubles partner which is not clearly legal shall be considered incorrect.
2.06.07 Exceptionally, the umpire may relax the requirements for a correct service where he or she is satisfied that compliance is prevented by physical disability.