Monday 17 October 2016

NodeJS Interview Questions and Answers for

NodeJS Interview Questions and Answers

Question: Node.js is best suited for what type of application?
Node.js is best suited for real-time applications like Online games, Collaboration Tools, Chat Rooms etc where Real time data required without Refreshing the page.


Question: Why I should use NodeJS ?
  1. Best for Real Time Application.
  2. Javascript can be run in client side as well as in Server Side.
  3. Easy to Setup.
  4. Its lightweight and Fast.
  5. Well suited for applications that have a lot of concurrent connections.
  6. Free modules available like socket, MySQL etc



Question: Why I should Not use NodeJS ?
  1. It runs Javascript, which has no compile-time type checking.
  2. Nested callback hell.
  3. Dealing with files can be a bit of a pain.
  4. Not good for Blogs and static sites.



Question: How do I pass command line arguments to Node.js?
In Command Line
node test.js one two three four five

How to get data
var args = process.argv.slice(2);
console.log(args);



Question: How do I debug Node.js applications?
For you need to install node-inspector
npm install -g node-inspector



Question: How to list local packages installed?
npm list



Question: How to list global packages installed?
npm list -g



Question: How to exit in Node.js?
process.exit()



Question: How to parse JSON using Node.js??
JSON.parse()



Question: How to get GET (query string) variables?
var url = require('url');
var url_parts = url.parse(request.url, true);
var query = url_parts.query;
console.log(query);



Friday 14 October 2016

NodeJS Interview Questions and Answers for beginners

NodeJS Interview Questions and Answers for beginners

Question: What is NodeJS?
Node.js is a server-side platform.


Question: On which engine built on NodeJS??
Node.js is is built on Google Chrome's JavaScript Engine(V8).


Question: What type of application can be built using NodeJS?
  1. server-side application
  2. networking applications



Question: On which OS it can be run?
  1. OS X (Mac)
  2. Microsoft Windows
  3. Linux



Question: In what type of application we can use NodeJS?
  1. I/O bound Applications
  2. Data Streaming Applications
  3. Data Intensive Real-time Applications (DIRT)
  4. JSON APIs based Applications
  5. Single Page Applications



Question: What is REPL?
REPL is environment to test/debug the code of nodeJS.
Full form of REPL is Read Eval Print Loop.


Question: What is package.json?
package.json define the properties of a package like name, description, version, author, contributors and dependencies.


Question: Where does exist package.json in package?
It exist in root folder of every package.


Question: How to create an API in nodeJS?
var mysql = require("mysql");
var app = require('express')();
var http = require('http').Server(app);
var con = mysql.createConnection('mysql://arun:arun@localhost/enterprisedev2');

app.get('/get/records', function(req, res) {
    con.query('SELECT id,userName,text FROM users where usertype=3', function(err, rows) {
        res.send(rows);
    });
});



Question: How to escape a string while insert into database?
var mysql = require("mysql");
mysql.escape('userdata');