Howto: Check if image exists?

I have an image here: <project dir>/img/minimap/005.png
Code:
SE.TEST = SE.TEST || Utils.isOptionValid('test');
    SE.Minimap.minimapFolderPath = function()
    {
        var suffixPath = '/img/minimap/';
        if (!SE.TEST) { suffixPath = '/www' + suffixPath; }
        var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, suffixPath);
        if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
        path = decodeURIComponent(path);
        return path;
    }

    SE.Minimap.getFullMinimapPath = function(filename)
    {
        return SE.Minimap.minimapFolderPath() + filename;
    }

    // filename example: '002.png'
    SE.Minimap.minimapImageExists = function(filename)
    {
        var fs = require('fs');
        console.log(SE.Minimap.getFullMinimapPath(filename));
        return fs.existsSync(SE.Minimap.getFullMinimapPath(filename)); // <<<<<< always returns false.
    }
Sadly this function always returns false.
Console output: /img/minimap/005.png

Code to load image:
Code:
ImageManager.loadMinimap = function(filename, hue)
{
    return this.loadBitmap('img/minimap/', filename, hue, false);
};
this.mapBmp = ImageManager.loadMinimap(this.mapName);

Is this because I launch RPGMaker through Steam now? Does it change the executable path or something for the ImageManager? This used to work in the older version of RMMV when used with the standalone editor (=not Steam).

The code ImageManager.loadBitmap() always returns a BitMap, even if it does not exist on disk so I can't just do a null-check.
There are multiple issues.
1. decodeURIComponent... I don't see the use as justified. You don't have encoded filepath, so why decode it? All it does is change %20 etc. back to spaces.
2. window.location.pathname is not the way to go. NWJS of newer MVs is built to encrypt the filepath just to make it safer in case you need to share screenshots. So "isagjsadoigjsdgjhiojsgksfgasfksafgsk/img/minimap/002.png" is not a valid filepath.

Here's your fixed code. I also striped it of all unnecessary junk.
Code:
SE.Minimap.minimapImageExists = function(filename) {
    var fs = require ("fs");
    return fs.existsSync("./img/minimap/" + filename);
}
Note that the "./" was the way to go, it's the home folder. In C++ you must input the absolute path, not the relative path.
Thanks, it works now!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/howto-check-if-image-exists.113736/