Posts

Showing posts from November, 2021

Compress Payload in NodeJS

Image
Compress Payload (response) in NodeJS Compression  in  Node.js  and  Express.js  decreases the amount of downloadable data from a website or app. By using this compression, we can  improve the performance of our Node.js applications  as our  payload size is dramatically reduced above 70% . Compression  generally refers to code that has been modified using a data compression algorithm. Unlike  minification  that ends up providing perfectly valid code, compressed code must be unzipped before use. There are many text compression algorithms, but there are only  3 supported   algorithms for compression  (and  decompression ) of  HTTP requests: Deflate  ( deflate ): Not commonly used. Gzip  ( gzip ): The most widely used compression format for server and client interactions. It is based on the  Deflate  algorithm and is compatible with all current browsers. Brotli  ( br ): A newer compression algorithm that aims to further improve compression ratios, which can result in even faster page load

Simple NodeJs App with MQTT

Image
What is MQTT? MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. The protocol usually runs over TCP/IP, however, any network protocol that provides ordered, lossless, bi-directional connections can support MQTT. MQTT is used for  data exchange between constrained devices and server applications . It keeps bandwidth requirements to an absolute minimum, handles unreliable networks, requires little implementation effort for developers, and is, therefore, ideal for machine-to-machine (M2M) communication. Node JS Application using MQTT Create a publish file. (pub.js) const mqtt = require ( 'mqtt' ); const client = mqtt . connect ( 'mqtt://broker.hivemq.com' ); client . on ( 'connect' , function (){     setInterval (() => {         const random = Math . random () * 50 ;         console . log ( random )         if ( random > 26 ){             client . publish ( 'ATM01' , 'ATM 01 temperature is &