How to keep Terraria NPCS from letting monsters in?
Solution 1:
This has also always bugged me in my first days of Terraria. NPC's are programmed to walk to the left and right, even if there are doors in the way.
What I always do is that I build the NPC building on top of my house, or floating 8 blocks above the ground, so that the mobs can't reach them. From there I connect my base to the NPC building using platforms. Or whatever kind of block you prefer.
Either way, you can't just tell the NPC's not to use doors, the only time that they don't use them is during the night.
Solution 2:
You can build a door from three active stone blocks (created from stone + wire) wired to a switch. Neither NPCs nor enemies can open those doors. This solution is obviously only available once you have the Mechanic and can build such mechanisms.
The whole mechanism is shown in this screenshot, though with an additional lava moat in front of the door to kill enemies.
The door in the state where you can walk through
The door in the solid state when it looks just like regular stone wall.