Skip to content

Freely Import Other Functional Modules

JavaScript is one of the most popular scripting languages on the internet, present in all web front-ends and clients. As a C-like language, it has a broad user base and is easy to learn.

Node.js uses npm as its default package manager, which can automate the installation, update, and removal of project dependencies.

npm third-party package library: https://www.npmjs.com/

Any feature module that traditional programming can implement can be integrated into our pbottleRPA automation flows.

Database Module

Example of importing the mysql database. Other database modules work similarly:

javascript
// Import pbottleRPA functionality
const pbottleRPA = require('./pbottleRPA')
// Import third-party mysql connection functionality   Pre-execute command: npm install mysql
const mysql      = require('mysql'); // Pre-execute command: npm install mysql

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123456',
  database : 'test'
});
connection.connect();
 
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
  // Use pbottleRPA API
  pbottleRPA.tts("mysql result count: " + results[0].solution)
});

Image Processing Module

Example of importing the sharp image processing module:

javascript

const pbottleRPA = require('./pbottleRPA')  // Import pbottleRPA functionality
const sharp = require('sharp');  // Pre-execute command: npm install sharp

// Resize to specified width, height auto
sharp('input.jpg')
  .resize(300, null)
  .toFile('output.jpg');

// Maintain aspect ratio and limit within specified dimensions
sharp('input.jpg')
  .resize(300, 300, {
    fit: 'inside',
    withoutEnlargement: true  // Prevent image enlargement
  })
  .toFile('output.jpg');

Excel and Word Modules

First execute: npm install exceljs mammoth docx

  • See demo example: [Third Party] Read Write Excel Demo Script.mjs
  • See demo example: [Third Party] Read Write Word Demo Script.mjs

Generate PDF Module

Example of generating a simple PDF file:

javascript
const pbottleRPA = require('./pbottleRPA')  // Import pbottleRPA functionality
const puppeteer = require('puppeteer'); // Pre-execute command: npm install puppeteer

async function htmlToPdf(htmlContent, outputPath) {
  // Launch browser
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  // Set page content
  await page.setContent(htmlContent);

  // Wait for page load (optional)
  await page.waitForTimeout(1000); // Wait 1 second to ensure content is fully loaded (if needed)

  // Generate PDF
  await page.pdf({ path: outputPath, format: 'A4' });

  // Close browser
  await browser.close();
}

// HTML content example
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
  <title>Test Page</title>
</head>
<body>
  <h1>Hello, World!</h1>
  <p>This is a PDF generated using Node.js and Puppeteer.</p>
</body>
</html>
`;

// Output path
const outputPath = 'output.pdf';

// Call function to generate PDF
htmlToPdf(htmlContent, outputPath).catch(err => console.error('PDF generation failed:', err));

⭐⭐⭐⭐⭐