How can I find the last modified date of a JavaScript file? [closed]

I am working on a cache buster where the query parameter would be the last modified date of my js file.
But I am having some trouble getting the last modified date of my js file.

I have tried File() constructor and tried to use it’s lastModified property:

const file = new File([], "index.js");
    let script = document.getElementById('my-js');
    script.setAttribute('src', `index.js?v=${file.lastModified}`);

But I soon figured out that it won’t work because, if you don’t set the lastModified attribute of the File() constructor, it will assign the lastModified attributw to be Date.now().

This is not what I am looking for as I would still like to store the js file on cache unless any modifications have been made to the file but my current code will refresh cache every time the page is reloaded.