Is there code for door open direction
Unless the door opens directly into a set of stairs, doors can generally be installed to open in either direction. 

A lot of times bathroom doors are installed to swing outward because the bathroom is quite small, and this orientation allows for more options when placing the fixtures in the bathroom. It also gives the illusion of the room being bigger.

Another fairly popular option is to install a pocket door, where the door slides sideways into the wall, rather than swinging inward or outward. This requires some additional work, as you are essentially installing a door twice as wide as a normal door, and you need to ensure you have the proper structure for it.