Monday, 14 May 2018

Nodejs Interview Questions and Answer 2 year Experience

Question: How to encrypt a value with SECRET KEY?
const {SHA256} = require("crypto-js");
var SECRET_KEY='secretkey';

var message='I am good.';
var hash=SHA256(message+SECRET_KEY).toString();
console.log(`Message: ${message}`);
console.log(`Hash: ${hash}`);

You need to install the crypto-js module.

Question: How to encrypt and decrypt the String?
const jwt = require('jsonwebtoken');
var SECRET_KEY='secretkey';

var data = {
  id: 10

var token = jwt.sign(data, SECRET_KEY);
console.log(token);//Give you long string 

var decoded = jwt.verify(token, SECRET_KEY);
console.log('decoded', decoded);

Wednesday, 9 May 2018

How to backup of wordpress into S3?

How to backup of wordpress into S3?

Question: How to Store the backup of wordpress into S3?
aws s3 cp /var/www/html s3://website-bucket-akg/wordpress/ --recursive

Question: How to upload images in S3?
 aws s3 cp --recursive /var/www/html/wp-content/uploads s3://cloud-front-s3/wp-media

Question: How to Upload images to S3 Sync?
Lets test with --dryrun, first
aws s3 sync --delete /var/www/html/wp-content/uploads s3://cloud-front-s3/wp-media --dryrun

Now Run the command
aws s3 sync --delete /var/www/html/wp-content/uploads s3://cloud-front-s3/wp-media

Question: How to sync the images with S3 with help of cron?
*/3 * * * * aws s3 sync --delete /var/www/html/wp-content/uploads s3://cloud-front-s3/wp-media >> /var/www/html/cron/cron.log 2>&1

It run every 3 mins.