I am not being able to run my worker, it just keeps showing cannot find module whenever I try to execute my worker
I am using Node.js v20.13.1(LTS) and npm version 10.5.2.
Here’s the code of my worker (Additional_request.js):
import {
Client,
logger,
Variables,
File,
} from “camunda-external-task-client-js”;
import nodemailer from ‘nodemailer’;
// const additionalRequest = require(‘./Additional_request.js’); // Đường dẫn chính xác nếu cùng thư mục
// configuration for the Client:
// - ‘baseUrl’: url to the Process Engine
// - ‘logger’: utility to automatically log important events
const config = { baseUrl: “http://localhost:8080/engine-rest”, use: logger };
// create a Client instance with custom configuration
const client = new Client(config);
function sendEmail(to, subject, message) {
const transporter = nodemailer.createTransport({
host: ‘smtp.gmail.com’, // Replace with your email server host
port: 587,
secure: true,
auth: {
user: ‘22520476@gm.uit.edu.vn’, // Replace with your email address
pass: ‘**********’, // Replace with your email password
}
});
const mailOptions = {
from: ‘22520476@gm.uit.edu.vn’, // Replace with your email address
to: ‘hoang2004pkh@gmail.com’,
subject: “Yêu cầu bổ sung thông tin nhằm đổi mã PIN thẻ ATM”,
text: message
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error('Error sending email:', error);
} else {
console.log(`Email sent to ${to}: ${info.messageId}`);
}
});
}
// Subscribe to the topic "Additional_request"
client.subscribe("Additional_request", async function ({ task, taskService }) {
const missingFields = [];
const email = task.variables.get("kh_email"); // Get email from process variable
// Check for missing fields
if (!task.variables.get("kh_name")) missingFields.push("Tên khách hàng");
if (!task.variables.get("kh_sdt")) missingFields.push("Số điện thoại");
if (!email) missingFields.push("Email");
if (!task.variables.get("kh_cardid")) missingFields.push("Căn cước công dân");
if (!task.variables.get("accountid")) missingFields.push("Số tài khoản");
if (!task.variables.get("kh_cardtype")) missingFields.push("Loại tài khoản");
// Send email notification if missing fields exist
if (missingFields.length > 0) {
const message = `Xin chào ${task.variables.get("kh_name") || "Khách hàng"},\n\nChúng tôi nhận thấy bạn đã điền thiếu
thông tin để hoàn tất việc đổi mã PIN cho thẻ ATM.\nVui lòng bổ sung các thông tin sau:\n- ${missingFields.join("\n- ")}\n\nSau khi bổ sung đầy đủ thông tin,
vui lòng truy cập ... để tiếp tục quy trình.\n\nTrân trọng,\nHệ thống đổi mã PIN thẻ ATM`;
sendEmail(email, "Thiếu thông tin đổi mã PIN thẻ ATM", message);
}
// Complete the task (assuming logic is complete)
taskService.complete(task);
});
// Start the client
client.start();