Automating months of Hard Work

Visakh Vijayan
2 min readNov 17, 2023

--

We have been working on setting up a facility management SaaS product for a couple of months now. As we near the final stages, we thought it would be great to have a script that could set up a random facility so that it can be demoed/played around on a need basis.

Here is how we did that using our favorite stack Express and Node.

  1. We created a service file with a class called FakeFacilityService . This would essentially hold all the different functions needed to make the facility.
  2. We add a function called createFakeFacility(params). This takes the necessary details to create a facility. These are optional. So you could go ahead and skip if needed.
  3. We then added a script to our package.json with the command npm run fake:facility
  4. We created a worker script that looked something like this —
export default async function runFakeFacilityWorker(): Promise<Facility> {
// The params needed to make the facility
// The call to the service
}

if (require.main === module) {
runFakeFacilityWorker().then(() => { process.exit(); });
}

5. The process.exit() is so that the script can end gracefully once the facility is created. We devised it using a if block so that we can call the worker in our test suites as well. With this, it caters to both types of calls, test suites, and npm commands.

So from next time onwards, we just use the script, and the rest is taken care of. Somehow it feels like a hands-free version of our hard work. Mmm. Maybe we should not have made this script after all.

--

--

Visakh Vijayan

Techie from Kerala, India. Days are for coding, nights for weaving tales of tech, travel, and finance. Join me in exploring this multifaceted journey