Sugeng rawuh

PM2 for Node.js developers - settings in my application

Installing pm2

Firstly, pm2 should be installed globally to run several applications.

npm install pm2 -g

pm2 uses a configuration file to maintain the application.it can be either JSON or js or YAML file.

Here, we are going to use process.json file which will have the configuration for our application.

Application Setup

Create a simple node.js application with a file called app.js

npm init --yes

add the following code in app.js.

const express = require('express');

const app = express();

app.get('/',(req,res) => {

    res.send("PM2 is working, Send me Home");
    
})

const PORT = process.env.PORT;
app.listen(PORT,() => {
    console.log(`server is running on port ${PORT}`);
})

After that, create a file called process.json. it contains the apps array which contains the application configuration details.

{
    "apps": [{
        "name" : "nodepm2",
        "script" : "./app.js",
        "env" : {
            "PORT" : 4005
        },
        "env_production" : {
            "PORT" : 4000
        }
    }]
}

Firstly, name is the name of the process that pm2 running. pm2 will run the file mentioned in the script. Here, it will run like

pm2 start app.js

env contains the environment variable for the application. we can specify different env variables such as development, production or staging.

Here, we mentioned the environment variables for production and default(development).

Running pm2

Therefore, To run the application using pm2, we can start the application using the configuration of pm2.

pm2 start process.json
Share:

fix problem UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'default' of undefined

whatsapp-web.js from pedroslopez

I got an error yesterday, February 28, 2021

Error: Evaluation failed: TypeError: Cannot read property 'default' of undefined



fix
1. npm i whatsapp-web.js
2. npm audit fix


Share:

Mysql in Ubuntu 20 error Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted

 Message Error : Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted

Fix my Problem :

1. open terminal

2. write coment : sudo /opt/lampp/bin/mysql_upgrade

3. restart apache

4. finish. 


i had the error when created a stored procedure mysql

Share:

Cannot send email from VPS with CodeIgniter

Gagal mengirim Email Gmail dari VPS

Ternyata tidak hanya saya saja yang mengalamai kendala saat mengirim Email khususny Gmail dari website dengan menggunakan VPS. masalah ini sudah saya alami sejak 2013, dan hari ini saya mencoba kembali apakah masih sama dengan source code yang tentunya berbeda. Saya menggunakan CI 3 untuk saat ini, source code sesuai dengan library CI yang ada di documentasi ternyata tetap tidak bisa. 

Gmail, yahoo mungkin sangat ketat jadi kalau ada proses send email melalui port atau ip VPS dianggapnya kurang aman. 

Saya juga menggunakan Cloud Hosting, untuk masalah kirim email di hosting tidak ada masalah sama sekali. 

Fix problem untuk masalah saya sendiri

Dengan memanfaatkan Hosting yang ada, ahirnya saya membuat semacam API sendiri di Hosting untuk mengirim email dari VPS manapun, dengan memberikan hak akses kunci agar lebih aman lagi. 

Share:

Auto run node js if reboot system


Image : list pm2 , check after reboot system 

Auto run node js if reboot system

1. Install PM2 globally using NPM

npm install pm2 -g


2.Start your script with pm2

pm2 start app.js


3. generate an active startup script

pm2 startup


NOTE: pm2 startup is for startting the PM2 when the system reboots. PM2 once started, restarts all the processes it had been managing before the system went down. In case you want to disable the automatic startup, simply use pm2 unstartup If you want the startup script to be executed under another user, just use the -u <username> option and the --hp <user_home>:




Share:

Puppeteer can't launch chromium, missing shared library libgbm.so - ubuntu

sudo apt-get update

sudo apt-get install -y libgbm-dev

Share:

Update password root phpmyadmin ubuntu 20

 Try restart mysql-server before execution the comands

sudo service mysql restart

MYSQL-SERVER >= 5.7

sudo mysql -uroot -p
USE mysql;
UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
UPDATE user SET plugin="mysql_native_password";
FLUSH PRIVILEGES;
quit;

MYSQL-SERVER < 5.7

sudo mysql -uroot -p
USE mysql;
UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
UPDATE user SET plugin="mysql_native_password";
FLUSH PRIVILEGES;
quit;

Share:

Tonton video



Yuk, SUBSCRIBE

omfiki.blogspot.com