Q: How to check if url exist synchronously in NodeJs ? I would like to know if there is a way to check whether an URL exists synchronously. In fact I am downloading files so I need to make sure these URLs exists before trying to download them. Here is the package I am using to check if these URLs are valid https://github.com/boblauer/url-exists

A: In short, you can't.
You can't force an async request to be synchronous.
You have a couple different syntactical approaches (Promises, async/await, events via Node.js http, callbacks, etc), but it's all going to boil down to being async in some way.
The async/await pattern will look the most synchronous, but it will still be async.
The package you're using specifically uses the callback pattern, so you'll need to adjust your other code to be async. You can mix and match these approaches. 
My personal preference is to wrap non-Promise patterns into a Promise pattern, then use async/await syntax throughout. Again, this look synchronous, but keep in mind it isn't and deal with it accordingly.
You can wrap callback syntax as a Promise like this:
const urlExistsPromise = url => new Promise((resolve, reject) => 
    urlExists(url, (err, exists) => err ? reject(err) : resolve(exists));

And you can use it like this:
urlExistsPromise(url).then(exists => console.log(exists));

or as await (inside a function labeled async):
const exists = await urlExistsPromise(url);


A: You can use url-exist-sync:
const urlExistSync = require("url-exist-sync");

urlExistSync("https://google.com");
//=> true

urlExistSync("https://google.com/404ingURL");
//=> false


A: const urlExist = require("url-exist");

(async () => {
   urlExist("http://127.0.0.1:5000/").then(exists => 
      mainWindow.loadURL("http://127.0.0.1:5000/"));
  })();

This is what worked for me.
