How to parse JSON files in Node.JS ?

Quick tip using fs: let data = fs.readFileSync(“myFile.json”, ‘utf8’); console.log(typeof JSON.parse(data)); There is another way to do this that requires less effort. Using require directly, like so: const data = require(“myFile.json”); console.log(typeof data); Hope it helps.

How to pack NodeJS project into a tarball?

Today I needed to install my brand new NodeJS-developed CLI application in my computer. After a quick search on the Internet I became aware that NPM allows me to do that very easily. The command is: npm pack Run it inside the project that you want to pack (at the same level of the package.json file). Here is an example …

How to create a Node.JS application with Express Generator

I am assuming that you already have Node.JS installed. If you don’t, worry not! you can get your own copy today from the Node.JS download section! Using ExpressJS is very quick and easy. It generates all the file structure needed for a web application. You can select¬† any of the different views they have available, in this case I am …

How to Encrypt / Decrypt with AES (CCM & GCM) in Node.JS

First of all we have to understand what is CCM mode and GCM mode. Roughly: CCM CCM mode (Counter with CBC-MAC) is a mode of operation for cryptographic block ciphers. It is an authenticated encryption algorithm designed to provide both authentication and confidentiality. CCM mode is only defined for block ciphers with a block length of 128 bits. GCM Galois/Counter …

How to list supported Ciphers, Hashes, and Curves for Crypto in Node.JS

Not a complicated task. Here is the code: var crypto = require(‘crypto’); console.log(); console.log(‘[ SUPPORTED CIPHERS ]\n’) console.log(crypto.getCiphers()); console.log(); console.log(‘[ SUPPORTED HASHES ]\n’) console.log(crypto.getHashes()); console.log(); console.log(‘[ SUPPORTED CURVES ]\n’) console.log(crypto.getCurves()); Your output should be similar to this: E:\Codes\NodeJS\Cryptography>node listAllAlgorithms.js [ SUPPORTED CIPHERS ] [ ‘CAST-cbc’, ‘aes-128-cbc’, ‘aes-128-cbc-hmac-sha1’, ‘aes-128-cbc-hmac-sha256’, ‘aes-128-ccm’, ‘aes-128-cfb’, ‘aes-128-cfb1’, ‘aes-128-cfb8’, ‘aes-128-ctr’, ‘aes-128-ecb’, ‘aes-128-gcm’, ‘aes-128-ofb’, ‘aes-128-xts’, ‘aes-192-cbc’, ‘aes-192-ccm’, ‘aes-192-cfb’, …