Search for a file in directory by it's name (without knowing extension)

I want to find a file in a specific directory by it’s name and without knowing it’s extension

app.get("/test/:id", (req, res) => {
    const mongo_id = req.params.id;
    const file_path = __dirname + somepath + mongo_id + ".png"; // I should remove this extension but how to find file ?
    if (!existsSync(file_path)) return res.status(404).end() ; // Check if file exists

    res.sendFile(file_path) ;
})

As you see I am adding .png at the end of the path that I want to send it as a response but sometimes I want to save some files that they are not PNG file

Thank you

135 thoughts on “Search for a file in directory by it's name (without knowing extension)”

  1. Hi there, I discovered your website by the use of Google whilst searching for
    a related topic, your website came up, it looks great.
    I have bookmarked it in my google bookmarks.
    Hi there, just turned into alert to your weblog via Google, and located that it is really informative.
    I’m gonna be careful for brussels. I’ll be grateful when you proceed
    this in future. A lot of folks will probably be benefited out of your
    writing. Cheers! http://www.deinformedvoters.org/hydroxychloroquine

    Reply
  2. Hi there! This post could not be written any better! Reading
    this post reminds me of my good old room mate! He always kept chatting about this.
    I will forward this page to him. Fairly certain he will have a good read.
    Thank you for sharing!

    Reply
  3. Greetings from Ohio! I’m bored to tears at work so I decided
    to check out your website on my iphone during lunch break.
    I enjoy the knowledge you present here and can’t wait to take a look when I get home.
    I’m amazed at how fast your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyways, good blog!

    Reply
  4. Howdy just wanted to give you a quick heads up. The words in your content seem to be
    running off the screen in Opera. I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I figured I’d post
    to let you know. The style and design look great though! Hope you get the problem resolved soon. Kudos scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

    Reply
  5. I believe what you said made a ton of sense. But, think about this,
    suppose you were to create a killer headline? I am not saying your information isn’t solid, however what if you added a
    post title to possibly grab a person’s attention? I mean Search
    for a file in directory by it's name (without knowing extension) – JavaScript Help is a little
    plain. You might glance at Yahoo’s home page and see how they create news headlines to grab viewers interested.
    You might add a related video or a related pic or two to get people interested
    about what you’ve got to say. Just my opinion, it might bring your blog a little
    livelier. http://antiibioticsland.com/Bactrim.htm

    Reply
  6. Интернет-платформа Joycasino начала деятельность на просторах отечественного интернета в 2014 году.
    Клиентам веб-проекта предоставлен топовый софт от популярных разработчиков.
    В коллекцию цифровых развлечений вошли аппараты
    барабанного типа, лайв-игры и ставки
    на спорт и киберспортивные дисциплины.

    Reply
  7. Oi, você também está usando o wordpress como plataforma do seu site ?
    Eu sou novo no mundo do blog, mas estou querendo criar o meu próprio.

    Você aprendeu alguma programação para fazer
    seu próprio blog? Qualquer ajuda seria muito útil!

    Reply
  8. Greetingѕ! I know thhis iiѕ somehat off topic but I was
    wondering if you knew wᴡheгe I coul geet a captcha plugin for my comment form?
    I’m usibg tthe same blog plɑtfoгm as yoսrs and I’m having
    pгoblems finding one? Thanks a lоt!

    Feeel free to surf to my web site; info Lebih Lengkap

    Reply
  9. І believe that is among thee sso much significant info forr me.

    And i’m satisfked reading youyr article. Hoѡeеѵer want to statement on few basic issues, The web site taste is grеat,
    the artiсles is in point of fact excellent : D.
    Excellent task, cheers

    Look at my weeb age – slot online

    Reply
  10. Can I simply ѕaʏ whaat a comfort to discover a person thɑt acualⅼy understands what they are discusesing over tһe internet.

    You actually know how ttߋ bring a problem to light and make iіt important.
    More people need too looк at this and understand this side of the story.
    I was surprised that you’гe not more poⲣular given that you definitely possess thе gіft.

    Reply

Leave a Comment