It's generally used by parents or grandparents towards their children or grandchildren, but can also be used by other relatives or close friends in a friendly and affectionate way.
It's similar to terms like "son" or "sweetheart" in English, but with a more familiar and endearing connotation.