The prime minister's visit coincided with Infantry Day celebrations, which is observed to mark the landing of first Indian troops in Jammu and Kashmir in 1947 to push back Pakistan supported intruders.
Modi directly flew to the Army Brigade Headquarters in the border district to interact with the troops deployed along the LoC, the officials said.
This is for the third time that the prime minister visited Jammu and Kashmir to celebrate Diwali with the troops in the border state since 2014, and first after the abrogation of Article 370 provisions.
Modi started the practice of interacting with troops serving in tough areas on Diwali soon after taking over as the prime minister in 2014 when he had spent his Diwali at Siachen in Ladakh region with the Jawans, besides visiting the flood victims in Srinagar.
He visited Gurez sector of north Kashmir in 2017 and spent his Diwali with soldiers deployed there.
In 2015, he visited the Punjab border on Diwali. His visit coincided with 50 years of 1965 Indo-Pak War.
The next year, Modi was in Himachal Pradesh, where he spent time with Indo-Tibetan Border Police (ITBP) personnel at an outpost.
In 2018, he celebrated the festival with Army and the ITBP personnel in the icy terrain near the India-China border in Uttarakhand.