PM2 command to run ecosystem file

Once the file is properly configured in JSON format, run this command: pm2 start ecosystem.json The output should be similar to this: [PM2] Applying action restartProcessId on app [x509](ids: [ 0 ]) [PM2] [x509](0) ✓ ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user …

SCRYPT demo in Node.JS v15

SCRYPT is yet another password-based key derivation function that allows you to tweak its arguments in order to discourage brute-force attacks. Basically you can adjust the options to make it slower, and therefore brute-force attacks will need more time to be performed. Here is an example of how to use SCRYPT to generate keys and IVs to use with all …

Password Based Key Derivation Function 2 (PBKDF2) demo in Node.JS v15

A quick demo on how to use Password Based Key Derivation Function 2 (PBKDF2) to generate keys and IVs to use with all different ciphers available in Node.JS v15.x. const crypto = require(‘crypto’); const PASSWORD = “My_Secret_Password”; // Could be the password/key used to encrypt a message const ITERATIONS = 10; const DIGEST = “sha256”; crypto.getCiphers().forEach(cipher => { let cipherInfo …

Node.JS Ciphers Info in version 15.x

After the deprecation of methods createCipher(…) and createDecipher(…) due to the introduction of createCipheriv(…) and createDecipheriv(…) a lot of us had issues when specifying the keys and IVs because sometimes the key would be the incorrect size and same for the IVs. I developed a kind of brute force tester to determine the correct values and keep them in a …

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); Or you can create a function like this with fs also: function loadAlgorithms(fName) { let data = fs.readFileSync(fName, ‘utf8’); return JSON.parse(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. Important! Don’t forget to add this to your package.json file:  “bin”: {    “skynet”: “./bin/skynetApp.js”   }, It’s basically the name of the command and the NodeJS file it will execute, in this case the command name is skynet and every time this is typed in a terminal window it …

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 Encode / Decode to / from base64 in Node.JS

Today I ran into this basic problem. A quick search on google gave me the answer, I tested it, it worked, and the rest is history. Here is the code. let plainText = “Hello World!”; console.log(“Plaint text = ” + plainText); // Encoding to base64 let base64 = new Buffer(plainText).toString(‘base64’); console.log(“Encoded to base64 = ” + base64); // Decoding from …