Can I connect an external microphone to my Lumia 640 and record sound from it?
Yes, you can. In principle, there are three ways to connect an external microphone:
The 3.5 mm audio jack. You'll need a microphone with a 3.5 mm TRRS connector, or a suitable adapter if the microphone has a different connector (e.g. XLR). Note that TRRS merely determines the number of contacts in the connector (4 - tip, ring, ring, sleeve); different standards exist for which signal is passed through which connector. According to this AAWP article, first-gen WP8 Lumia phones (e.g. 820, 920) use a universal connector that works with the two most common standards (OMTP and AHJ), presumably the same applies to more recent Lumias as well, such as your 640.
Bluetooth. Microphones that support Bluetooth appear to be pretty rare and mostly designed for the video industry. You may also run into problems with connectivity and audio quality. I do not recommend this option unless you have requirements that a wired microphone will not satisfy.
USB. Unfortunately this is not possible on your Lumia 640 because older Lumia phones lack the capability to act as USB hosts. However, the newer Lumia 950 and 950 XL do support USB OTG and have been tested to work with external USB microphones.
For a lot more useful information, see Audio Recording With a Smartphone
This list of audio recording apps for Windows Phone might also be useful.