Historically, Sony have locked down PlayStation hard drives tighter than Fort Knox, with encryption that prevents users from swapping them between devices without losing all of their data. However, with the release of system software update 4.50, it is now possible to use an external hard drive to transfer games between PS4s.
First, you'll need to attach a USB 3.0 HDD to your console and set it up - full instructions for doing this can be found in our guide for how to use an external hard drive for extended storage on your PS4. Here's advice on where to find a good PS4 external hard drive. When it's ready, either download some games onto the external drive, or transfer them from the internal drive using the Move to Extended Storage option found under Settings > Storage > System Storage > Applications.
With the games now stored on the external hard drive, you can take it and plug it into a different PS4, where the games should appear on the home menu screen. As long as you're logged in on the PSN account which owns the games and are signed in online, you can then launch them and start playing immediately. This means that you can store a game on your external drive, then take it over to a friend's house and play it on their console without having to download it all over again - very handy for those 50GB+ installs.
One thing to note - game saved data cannot be stored on an external hard drive being used for extended storage, so if you want to continue your progress then you'll need to transfer your saved data between consoles using either PlayStation Plus online storage or a separate USB device.