Wednesday, 1 July 2020

Node JS Interview Questions and Answers for 3 Years experience



Question: What is the difference between tilde(~) and caret(^) in package.json?
~ update you to all future patch versions, without incrementing the minor version. ~2.2.3 will use releases from 2.2.3 to 2.3.0.
^ update you to all future minor/patch versions, without incrementing the major version. ^2.3.3 will use releases from 2.3.3 to 3.0.0.



Question: How do I pass command line arguments to a Node.js program?
In Node - How to pass arguent
node process-2.js one two=three four
In Node - How to get argument value
process.argv



Question: How do I update each dependency in package.json to the latest version?
npm i -g npm-check-updates
ncu -u
npm install



Question: How can I update NodeJS and NPM to the next versions?
npm install -g npm



Question: How to write in files synchronous in Node.js?
const fs = require('fs');
fs.writeFileSync('/fold/test.txt', 'Write in file');



Question: How to read environment variables?
var mode   = process.env.NODE_ENV;
var apiKey = process.env.apiKey; 



Question: How to parse JSON using Node.js?
//Parse JSON Data
var bodyParser = require('body-parser')
app.use(bodyParser.json());       // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({// to support URL-encoded bodies
    extended: true
}));



Question: How  an HTTP POST request made?
var request = require('request');
request.post(
    'https://www.example.com',
    { json: { key: 'value' } },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body);
        }
    }
);



Question: How can I get the full object in Node.js's console.log(), rather than Object?
const util = require('util');
console.log(util.inspect(myObject, {showHidden: false, depth: null}));

OR
console.log(JSON.stringify(myObject, null, 4));




Question: How to encode a text using base64?
Buffer.from("Hello World").toString('base64'); //SGVsbG8gV29ybGQ=


Question: How to decoded a text which is encoded with base64?
Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'); //Hello World


Thursday, 18 June 2020

Get Mysql Row size too large error when change engine from MyISAM to Innodb

Get Mysql Row size too large error when change engine from MyISAM to Innodb
ALTER TABLE table_name ENGINE=InnoDB

When i try to change the engine From MyISAM to InnoDB, getting following error.

row size too large (> 8126). changing some columns to text or blob or using row_format=dynamic or row_format=compressed may help.

Solutions:
  1. Add the following to the my.cnf file under [mysqld] section.
            innodb_file_per_table=1;
            innodb_file_format = Barracuda;
            innodb_log_file_size = 256M    
    
         
  2. ALTER TABLE table_name ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;