My First Open Source Contribution Experience

Photo by Finn Hackshaw on Unsplash

This week I got an opportunity to work on Filer web filesystem project. Check out this link to know more about the project.

Throughout the whole time, I got hands-on experience on both Github and Git.

At first, I was confused between Git and Github.

Later, I found out…

Git is Version Control System.

GitHub is a web-based service for version control using Git.

In easy words…

Git helps us to keep track of our files and any changes made to those files on our local machine.

Github is a website that contains source code in different repositories managed through Git.

You can install Git through this link. Also, you need a GitHub account in order to make a contribution to any Open Source Project on GitHub.

How can I contribute to Open Source Society?

Well, there are so many ways……

Now, I am going to show you how I contributed to the Filer project on the GitHub

1) Firstly, I navigated to the Filer project on the GitHub.

2) Then, I forked the project by clicking on the button as shown in the image below

By forking, GitHub created a repository under my GitHub account.

3) After forking, I cloned the filer project on my local machine.

To clone the project click on the green button “Clone or download” and copy the link. You can either use a “Clone with SSH” or “Clone with HTTPS”.

Tip - Use "clone with ssh" to save your time in the future. With  ssh, you don't have to input your GitHub credentials and other details later when creating a pull request. But beforehand, you need to set-up an ssh key. Refer to this link to set up an ssh key. 

4) I opened my code editor (Visual Studio Code) and created a repository on my local machine by using git clone command shown below

git clone

5) After the cloning, I used “npm test” to make sure everything installed properly.

6) Now, it was time to either find a good bug or issue a bug.

You can find lots of bugs under the “Issues” tab.

I decided to file an issue.

So, I browsed around the code for some time and then I found files in which some of the variables use “var” as a data type which quite outdated. According to ES6 declaration style, “let” and “const” should be used to declare any variable in JS. Refer to this link to know more about ES6 declaration style.

7) Since it was my first time reporting a bug on GitHub so I just chose one file i.e. fs.readdir.spec.js filing for the issue.

Link of my issue page.

Soon I was assigned to fix the issue.

Now, It was time to code

8) I opened the earlier cloned project on Visual Studio Code and opened the fs.readdir.spec and changed the “var” declared variables with either “const” and “let” as shown below

9) After the required changes, I again executed “npm test” to check the code.

10) I used “git add” to stage the changes

git add fs.readdir.spec.js


git commit -m "Fixed #667: Replaced var with either const or let and added strict mode in fs.readdir.spec.js"

And later,

git push origin issue 667

It generated a link through which I was able to create a pull request for the filer project.

Link of my pull request.

Almost done,

After pull request, GitHub generated a CodeCov Report using Travis CI.

Luckily, I passed all the checks with 86.71% coverage.

You can review my changes through the “Files changes” tab. (link)

Red lines represent lines before changes and green lines represent after changes.

In the end, I reviewed other developer’s pull request.

Review 1

Review 2

Review 3


While reviewing (Review 1) pull request I found one of the contributors recommended to use ‘use strict’ at the top of the file. Then I found ‘use strict’ prevent certain actions from being taken and catches any thrown exceptions. (link) So, I added the ‘use strict’ at the top of the “fs.readdir.spec.js”. And, recommended other developers to add ‘use strict’ at the top of their file(Review 3).

Also through (Review 2), I found ‘const’ is more preferred over ‘let’ when variables aren’t changing their values. So, I changed variables declared with ‘let’ to use ‘const’ in “fs.readdir.spec.js”.

There were a few times when I was lost during the process of creating a pull request on GitHub but anyhow I figured it out through quick Google searches.

Tip - Listen to music while doing reasearch on Google (Really helps!)

In the future, I will ask my fellow developers for assistance to save some time.

Overall, I really enjoyed the whole process and I am looking forward to contributing more to the Open Source Society in the future.


NodeJS: Check whether a file exists or not with fs

Photo by Markus Spiske on Unsplash
Warning: Don't use fs.exists(path, callback) as it is deprecated.
Reason: The fs.exists method uses a callback that is inconsistent with other Node.js callbacks.

What should we use then?

The fs.existsSync(path) method can be used as it does not use any callback.

It takes one argument i.e. path as a string and returns true if the file exists and vice versa.

An example is shown below:

var fs = require('fs');

// fs.existsSync(path) returns boolean
if (fs.existsSync(path)) {
    console.log('File exists!');
} else{
    console.log('Sorry, File does not exists!');

Usually, it’s not recommended to use fs.existsSync as it can break your asynchronous code due to unnecessary blocking.

So, what’s the next option?

Well, according to the latest Node.js v11.7.0 Documentation, fs.stat(path[, options], callback) and fs.access(path[, mode], callback) are suggested as alternatives.

Lets, look more deep into it!

1) fs.access(path[, mode], callback)

It takes three arguments as follows:

  • path – string for a file path
  • mode- an optional argument, specifies the accessibility checks to be performed
  • callback – invokes if an error occurs
const file = 'package.json';

// Check if the file exists in the current directory.
fs.access(file, fs.constants.F_OK, (err) => {
  console.log(`${file} ${err ? 'does not exist' : 'exists'}`);

// Check if the file is readable.
fs.access(file, fs.constants.R_OK, (err) => {
  console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);

// Check if the file is writable.
fs.access(file, fs.constants.W_OK, (err) => {
  console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);

// Check if the file exists in the current directory, and if it is writable.
fs.access(file, fs.constants.F_OK | fs.constants.W_OK, (err) => {
  if (err) {
      `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
  } else {
    console.log(`${file} exists, and it is writable`);

According to NodeJS documentation, if a user wants to check file existence without manipulating it afterward, fs.access() is recommended. As it checks the existence of a file without opening it.

2) fs.stat(path[, options], callback)

It takes three arguments as follows:

  • path – string for a file path
  • options – an optional argument, an object which holds the value of bigint.
  • callback – returns error or Stats object depending if an error occurred or not.
var fs = require('fs');

fs.stat('path', function(err) {
    if (!err) {
        console.log('File exists!');
    else if (err.code === 'ENOENT') {
        console.log('Sorry, file does not exist!');
    }else {

Returns an object Stats with lots of elements as given below:

Stats {
 dev: 3803513792,
 mode: 33206,
 nlink: 1,
 uid: 0,
 gid: 0,
 rdev: 0,
 blksize: undefined,
 ino: 281474976744241,
 size: 227700,
 blocks: undefined,
 atimeMs: 1518123325605.2195,
 mtimeMs: 1456549122349.375,
 ctimeMs: 1456549122349.375,
 birthtimeMs: 1518123325605.2195,
 atime: 2018-02-08T20:55:25.605Z,
 mtime: 2016-02-27T04:58:42.349Z,
 ctime: 2016-02-27T04:58:42.349Z,
 birthtime: 2018-02-08T20:55:25.605Z }

How to check if a file exists before reading or writing on a file?

If a user wants to check for the existence of a file before reading or writing, then a user should do it directly and handle the error manually as shown below:

Check before writing on a file'myfile', 'wx', (err, fd) => {
  if (err) {
    if (err.code === 'EEXIST') {
      console.error('myfile already exists');

    throw err;


Check before reading a file'myfile', 'r', (err, fd) => {
  if (err) {
    if (err.code === 'ENOENT') {
      console.error('myfile does not exist');

    throw err;


Refer to official NodeJS documentation for more information.