Lab 1 OSD600

Thanks for joining me!

The node.js module feature that I will be talking about in this blog post is fs.exists(path, callback) and fs.existsSync(path).

Feature: fs.exists(path,callback)

This feature is used to test whether or not the given path exists by checking with the file system. If the path does not exists it calls the callback argument with either true or false.

Screenshot (53)

The fs.exists() callback has only one boolean parameter, which is why fs.access() is recommended instead of fs.exists().

It introduces a rare condition when fs.exists() is used to check if a file exists before calling

Feature: fs.existsSync(path)

This is a synchronous version of fs.exists(). Returns true is if the file exists, false otherwise.

Difference between synchronous or asynchronous: An asynchronous function is a code block within the function that is mostly non-blocking to the end user and user will not be prevented to perform different actions for various sub-processes. Synchronous is the opposite of asynchronous and is never recommended.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.