Latest in Data Processing
Home → Data Processing
How to create a simple Node app to generate PDF from HTML
Node offers lots of options for data processing and conversion. One of the common scenarios is converting websites to PDF or PNG.
Detect user country by IP in Node.js
 It shouldn't be hard to detect a user's country based on the IP address, right? Right... I really liked the simplicity of 
Prerequisites Before you install the module, you will need to download the BIN file by registering at ip2location and choosing the appropriate option. You will have a choice between the country, country + city, or other options....
ip2location module: load the BIN file, get the location, and close the BIN file.Prerequisites Before you install the module, you will need to download the BIN file by registering at ip2location and choosing the appropriate option. You will have a choice between the country, country + city, or other options....
Convert all JPGs and PNGs in a folder to WEBP and AVIF with Node.js and Sharp
 One of the easiest ways to convert all JPG and PNG images in a folder to WEBP and AVIF is to use the Sharp library.
Let's get straight to the point. We will need to install
   
Let's get straight to the point. We will need to install
sharp and glob.npm install --save glob sharpConvert all PNGs in a folder to WEBP with FFmpeg
 FFmpeg is an awesome tool that can convert not only videos but also audio and images. 
On Linux and Mac, run it like this in the folder where you want the conversion to run:
   
   
On Linux and Mac, run it like this in the folder where you want the conversion to run:
for i in *.png; do ffmpeg -y -i "$i" -c:v libwebp "${i%.*}.webp"; doneFOR /F "tokens=*" %G IN ('dir /b *.png') DO ffmpeg...Convert bytes to megabytes, gigabytes, terabytes without a loop.
 What if I tell you you can convert bytes to petabytes without doing a loop and constantly dividing by 1024?
      
The developers of Next.js created this neat library called Satori, which allows to convert JSX elements with style properties into SVG. As a result, this gives amazing possibilities:
You can generate HTML previews. For example, you can generate a simple JSX element on the server, convert to SVG, and then later convert it to JPG or...
function bytesToHuman(bytes) { let prefixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; let base = 1024; let cl = Math.min(parseInt(Math.log(bytes) / Math.log(base), 10), prefixes.length - 1); return (bytes / Math.pow(base, cl)).toFixed(2) + ' ' + prefixes[cl]; } console.log(bytesToHuman(1024 * 1024 * 10)); // 10.00 MB console.log(bytesToHuman(2151099283)); // 2.00 GBThe developers of Next.js created this neat library called Satori, which allows to convert JSX elements with style properties into SVG. As a result, this gives amazing possibilities:
You can generate HTML previews. For example, you can generate a simple JSX element on the server, convert to SVG, and then later convert it to JPG or...