Tech Rescue
  • Home
  • Acronyms
  • Cheat-Sheets
  • User Manuals

Node.JS

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.
Hector Perez Jul 18, 2017

How to generate SHA256HMAC in Node.JS

Today I had to do this for my job (hash some info) and I think is a good opportunity to share the knowledge. Here is the code, you can simply copy it and paste it in a file called SHA256Hmac.js and run it. let crypto; try { crypto = require('crypto')
Hector Perez Mar 17, 2017

How to convert a String into JSON object in Node.JS

Just a few days ago I needed to do this and I found this useful function. Very simple: var jsonStr = "{"firstName":"Siry", "lastName":"Mazari"}"; console.log('JSON String: %s', jsonStr); var jsonObj = JSON.parse(jsonStr); console.log('First Name: %s', jsonObj.firstName); console.log('Last Name: %s', jsonObj.lastName); The
Hector Perez Jul 18, 2016
Tech Rescue © 2025. Powered by Ghost