The National Electrical Code requires the placement of an electrical outlet no further than 6 feet from a door. However, there is no code stating how close to a door an outlet can be installed. Therefore, you can install an electrical outlet as close to a door as you desire.
Video of the Day
If an electrical cord is plugged into an outlet close to a door, it could cause damage by striking it. Additionally, it could become entangled in the door and be yanked from the outlet. It is also possible for an electrical cord to get pinched between the door and the jam.
Installing an electrical outlet is as much about convenience as it is need. If there is no practical location other than behind a door, then you have little choice. Weigh your willingness to bear the consequences and risks against the convenience of the outlet’s location.