Writing A Node.js tool to bookkeep my software engineering job applications

Applying for software engineering jobs needs some bookkeeping and that bookkeeping takes time over a lot of repeatable mouse clicking hence I decided to make a tool to spare me some more time utilized better else where.

Since I am currently applying for software engineering jobs and keeping track of where I applied and what customized resume I used for the company as well as the application. A lot of repeatable mouse clicking is going on from making the folder to copying the resume (CV) and cover letter into that folder. That folder that is created must be put on a folder named the same name as the current month of the year. This takes time that maybe better else where utilized. Hence I decided to make a tool that will free me of a lot of repeatable mouse clicking. Still will need to do some mouse clicking but way less now. My plan is just to create a folder that has a `-` in the name on the root directory and then gets slotted into the equivalent month and gets `Resume.docx` and `Cover Letter.docx` automatically copied into as well as creating a `link.txt`. That will allow me to customize the resume and cover letter used in the job application's folder. As a tool this is not a hard task in fact a quick [Node.js ](https: //nodejs.org/en/) script. I thought of making it completely automated whereby I only enter to a user interface the relevant things but that would take days to go through and finish and test. This article will asumme you know [Javascript](https://www.javascript.com/)/Node.js. The complete tool is found on my Github: [https: //github.com/Morr0/JobOrganiser](https://github.com/Morr0/JobOrganiser) ### Experimenting by listing all directories ```javascript const fs = require("fs"); const path = require("path"); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); (async () => { while (true){ await sleep(1000); const dirs = fs.readdirSync("."); dirs.forEach(item => console.log(item)); } })(); ``` Now here there is a while loop that sleeps for 1000 ms or 1 second and lists all directories in the current directory denoted by the linux `.` which means the current directory. The sleep function is basically calling `setTimeout` which is a Node.js way of waiting. The `fs` file system module is used to abstract OS file system operations. ### Adding the necessary constants: ```javascript const separator = '-'; const resumeName = "Resume.docx"; const coverLetterName = "Cover Letter.docx"; const linkFile = "link.txt"; const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; ``` Now the `separator` is my predicate, i.e. if a directory has it then that directory is one am looking for. The 3 constants below are just the names of files involved that I described above in the scenario. The next thing is an array of month names in English. Since Node.js doesn't have an API that tells me a month name except has `new Date().getMonth()` which is [ 0-11 ] describing month numbers. ### Adding the logic necessary: Now will change the body of the while loop to have the following: ```javascript await sleep(1000); const dirs = fs.readdirSync("."); for (const i in dirs){ const dir = dirs[i ]; if (dir.includes(separator)){ console.log(dir); await putInRespectiveFolder(dir); fs.rmdirSync(dir); } } ``` Note that this `for` loop looks like a `foreach` loop in other [C-Family programming languages ](https: //en.wikipedia.org/wiki/List_of_C-family_programming_languages) except here the `i` constant is just an index that we use it to refer to the array `dirs` which are the directories. Then we use a string function to check if the directory name has a `-` in it. Note that am awaiting the `putInRespectiveFolder` function which I will define below. ```javascript const putInRespectiveFolder = async (dir) => { const month = months[new Date().getMonth() ]; const dirLocation = path.join(month, dir); if (!fs.existsSync(path.join(month))){ fs.mkdirSync(month); } fs.mkdirSync(dirLocation, {recursive: true }); fs.copyFileSync(resumeName, path.join(dirLocation, resumeName)); fs.copyFileSync(coverLetterName, path.join(dirLocation, coverLetterName)); fs.writeFileSync(path.join(dirLocation, linkFile), ""); }; ``` First thing here is getting the month name, then using `path` which is the `require('path')` module I included above to construct a path. Then checking if a directory exists with the month name. If not then create one. Then will create a directory inside the month directory to house the job application. Note the use of `recursive: true` as an options parameter, this will not try to create the month directory everytime, i.e. it will check for it first. Setting it to false will cause an error each time and may cause unexpected behaviour if any of the directories existed. Then just copying the required files and then making a new `link.txt` file as empty which then I will write to it the URL of the job application. ### Notes: Now that the application is done, running it: ```bash node app.js ``` Now by just moving the `app.js` file to wherever you want to use it and run it. I will make some notes: - I have hardcoded the file names I am using because their names won't change - Note I could've used asynchrnonous version of the I/O operations but didn't as I need to promisify them all which will take some more lines of code - Even though I didn't use asynchronous versions of the `fs`, I have made the functions async for the reason to minimise processing and nothing else - The `path` module abstracts OS-specific file/directory namings, as in Windows folders are separated by `` whereas Linux by `/`, this module takes care of that. - The `fs` functions are named after Linux POSIX operations such as `mkdir` or `rmdir`. The program could use no hardcoding by including the names of files outside as environment variables or pass them as arguments but I saw no need for my case for more complexity. ### Conclusion: This is an easy tool that will save me/you minutes for each job applying session. Some references are: - [https: //nodejs.org/api/fs.html](https://nodejs.org/api/fs.html) - [https: //nodejs.org/api/path.html](https://nodejs.org/api/path.html) - [https: //nodejs.org/api/timers.html](https://nodejs.org/api/timers.html)