Postingan

Menampilkan postingan dari Juni, 2023

Run a Node.js script as a background process

To run a Node.js script as a background process, you can use various methods depending on your specific requirements and the operating system you are using. Here are a few options: 1. Using a process manager (e.g., PM2): - Install PM2 globally by running npm install -g pm2 . - Start your Node.js script as a background process using PM2: pm2 start your_script.js - PM2 provides additional features like process monitoring, automatic restarts, and log management. 2. Using the nohup command: - Open a terminal and navigate to the directory where your Node.js script is located. - Run the following command: nohup node your_script.js & The nohup command ensures that the script continues running even if the terminal session is closed. 3. Using the screen command: - Install screen if it is not already installed by running sudo apt install screen . - Open a terminal and run the following command to start a new screen session: screen -S session_name - With...

Whatsapp-web.js On Ubuntu Server

If you are encountering issues with launching the browser while trying to load the QR code using whatsapp-web.js on an Ubuntu server, you can try the following approach: First, make sure you have installed the necessary dependencies, including whatsapp-web.js, qrcode-terminal, and a headless browser like puppeteer: npm install whatsapp-web.js qrcode-terminal puppeteer Next, create a file called index.js and paste the following code: const qrcode = require('qrcode-terminal'); const { Client } = require('whatsapp-web.js'); const puppeteer = require('puppeteer'); // Path to store session data const SESSION_FILE_PATH = './session.json'; // Initialize the WhatsApp client const client = new Client({ session: require(SESSION_FILE_PATH), puppeteer: { executablePath: '/usr/bin/chromium-browser', // Change this path to your Chromium executable headless: true, args: ['--no-sandbox', '--disable-setuid...