Published on

How to use NodeJS in Browser Automation Studio

Authors

Using BAS allows you to create automation tools without knowing how to program or a programming language. With the current features of BAS, I think you can do most of the basic needs. However, in some cases, to handle faster or more complex tasks, writing code will be better.

In this article, I will guide you on how to use NodeJS in BAS through specific examples.

Suppose there is a problem like this: A customer needs to create temporary emails for use, you will need a tool to create bulk emails and export to a file with information including email and corresponding password.

Of course, this problem is simple and there are certainly many ways to complete it, but for the scope of this article, let's use NodeJS.

1. Create new project and enable NodeJS.

Open BAS and create a new project, then click Record to edit the script. Then click the installation button that I have circled in red as shown below:

How to use NodeJS in Browser Automation Studio

As you can see there are many versions of NodeJS, click on the appropriate version. Usually, you will choose the latest version.

How to use NodeJS in Browser Automation Studio

In case you need to use other packages or modules, click on Add npm module and add all the modules you need.

How to use NodeJS in Browser Automation Studio

Back to the original problem, I plan to use a temporary email service called mail.tm. This service provides a library for use in NodeJS called @cemalgnlts/mailjs. So let's add this module to the project.

Now click on the OK button to confirm. BAS will restart the script and install NodeJS along with the selected modules. After the installation is complete, the script will reopen the Record feature.

How to use NodeJS in Browser Automation Studio

2. Write your code

In the list of functions, type nodejs to search and select the correct function as I circled in red in the image below:

How to use NodeJS in Browser Automation Studio

Now I will use the mailjs library to create a temporary email address. The simple code is as follows:

const Mailjs = require("@cemalgnlts/mailjs");

const mailjs = new Mailjs();

const mailAccount = await mailjs.createOneAccount();

console.log(mailAccount.data);

Now you press run this function and see if the result is as below:

How to use NodeJS in Browser Automation Studio

So the code has been run, the email with password has been created. Now the only remaining job is to save this information to the file. I will not mention this part because you probably already know how, right?