Pages

Saturday, April 20, 2019

Nodejs handling uncaught exceptions globally

For unhandled exceptions:
process.on('uncaughtException', err => {
  console.error('There was an uncaught error', err)
  process.exit(1) //mandatory (as per the Node.js docs)
})

Here  uncaughtException event listener will be called for every such scenario.

Source: here

For unhandled Promise rejection:


process.on('unhandledRejection', err => { console.error('There was an uncaught error', err) process.exit(1) //mandatory (as per the Node.js docs) })


Here unhandledRejection event listener will also be called for every such scenario.

Monday, April 8, 2019

SemVer := Semantic Versioning

Here we are limiting our discussion for node.js semver

For nodejs itself and other npm packages: we see the versioning

j.n.p [ 3 group of digits ] e.g. 2.12.34

j = Major
n = Minor
p = Patch

For a package author the convention of version management is as follow:


  • Increment of Major version: Incompatible API Changes
  • Increment of Minor version: Added functionality with backward compatibility
  • Increment of Patch version: backward compatible bug fixing is added


Presiding Symbols of SemVer:

When npm install/update is run, package versions prepended with

~ will update only patches of the specified major and minor

^ will update only minors of the specified Major

|| logical or operation; either of the packages will be updated for example use 1.0.0 || >=1.1.0 <1.2.0 to either use 1.0.0 or one release from 1.1.0 up, but lower than 1.2.0.

= or no symbol - exactly mentioned package version

<   less than this Major, minor and patch
<= less than or equal to this Major, minor and patch
>   more than this Major, minor and patch
>= more than or equal to this Major, minor and patch


Only latest will update to the latest version.



Monday, April 1, 2019

MySQL master-slave replication configuration

Changes in configuration (mysqld.cnf) file:

For Master:


bind-address =0.0.0.0 [to listen all interfaces]
server-id = 1
For Salve:


bind-address =0.0.0.0 [to listen all interfaces]
server-id = 2

Both Master and Salve MySQL servers need to restart to make changes effective.

Replication commnads in mysql commnad prompt as root user/super admin

For Master:


-- user creation is optional; an existing user can be granted but 
-- need need to be publicly accessible.

mysql > create user 'replication_user'@'%' identified by 'MASTER_PASSWORD';
mysql > GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';
mysql > FLUSH PRIVILEGES;

-- After granting privilege the below command is the mean to collect 
-- master info to be used in salve


mysql> show master status; 

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      154 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)


For Slave:


mysql> stop slave; 
mysql> CHANGE MASTER TO MASTER_HOST = '<MASTER_HOST_IP_OR_ADDRESS>',MASTER_USER = 'replication_user', MASTER_PASSWORD = 'MASTER_PASSWORD'MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 154;
mysql > start slave;



** MASTER_LOG_FILE and MASTER_LOG_POS will be according to the values found by " show master status "
Source and Details: here