Q1 : What are the features of Node.js?
A : Node.js is a single-threaded but highly scalable system that utilizes JavaScript as its scripting language. It uses asynchronous, event-driven I/O instead of separate processes or threads. It is able to achieve high output via single-threaded event loop and non-blocking I/O.
Q2 : In which Language Node Js is written ?
A : Node js is written in C, C++,JavaScript.It uses Google’s open source V8 Javascript Engine to convert Javascript code to C++.
Q3 : Who is the author of Node Js ?
A : Node Js is written by Ryan Dahl.
Q4 : Explain Modules in Node Js ?
A : Modules are reusable block of code whose existence does not impact other code in any way. It is not supported by Javascript. Modules are introduced in ES6. Modules are important for Maintainability, Reusability, and Namespacing of Code.
Q5 : For what require() is used in Node Js ?
A : require() is used to include modules from external files in Node Js. It is the easiest way to include a module in Node. Basically require is a function that takes a string parameter which contains the location of the file that you want to include. It reads the entire javascript file, executes the file, and then proceeds to return the exports object.
Syntax:
require('path');
Q6 : Is Node.js Single-threaded ?
A : Yes, Node Js is single threaded to perform asynchronous processing. Doing async processing on a single thread could provide more performance and scalability under typical web loads than the typical thread-based implementation.
Q7 : Explain event loop in Node Js ?
A : In Node Js processes are single threaded, to supports concurrency it uses events and callbacks. An event loop is a mechanism that allows Node.js to perform non-blocking I/O operations.
Q9 : List some features of Express JS.
A : Some of the main features of Express JS are listed below: –
- It is used for setting up middlewares so as to provide a response to the HTTP or RESTful requests.
- With the help of express JS, the routing table can be defined for performing various HTTP operations.
- It is also used for dynamically rendering HTML pages which are based on passing arguments to the templates.
- It provides each and every feature which is provided by core Node JS.
- The performance of Express JS is adequate due to the presence of a thin layer prepared by the Express JS.
- It is used for organizing the web applications into the MVC architecture.
- Everything from routes to rendering view and performing HTTP requests can be managed by Express JS.
Q10 : What do you mean by Express JS?
A : Express JS is an application framework which is light-weighted node JS. A number of flexible, useful and important features are provided by this JavaScript framework for the development of mobile as well as web applications with the help of node JS.
Q11 : What is the use of Express JS?
A : Express.js is a lightweight web application which helps in organizing the web application into MVC architecture on the server side.
Q12 : How can models be defined in Express JS?
A : Below are the few reasons why to use Express with Node.js
- Express js is built on top of Node.js. It is the perfect framework for ultra-fast Input / Output.
- Cross Platform
- Support MVC Design pattern
- Support of NoSQL databases out of the box.
- Multiple templating engine support i.e. Jade or EJS which reduces the amount of HTML code you have to write for a page.
- Support Middleware, basic web-server creation, and easy routing tools.
Q14 : What are the two types of API functions in Node.js ?
A : The two types of API functions in Node.js are
a) Asynchronous, non-blocking functions
b) Synchronous, blocking functions
Q15 : Why node.js is quickly gaining attention from JAVA programmers?
A : Node.js is quickly gaining attention as it is a loop based server for JavaScript. Node.js gives user the ability to write the JavaScript on the server, which has access to things like HTTP stack, file I/O, TCP and databases.
Q16 : Mention the steps by which you can async in Node.js?
A : By following steps you can async Node.js
a) First class functions
b) Function composition
c) Callback Counters
d) Event loops
Q17 : How Node.js overcomes the problem of blocking of I/O operations?
A : Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.
Q18 : What are the Challenges with Node.js ?
A : Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.
Q19 : What does it mean “non-blocking” in node.js?
A : In node.js “non-blocking” means that its IO is non-blocking. Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.
Q20: What is the command that is used in node.js to import external libraries?
A : Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.
Q21 : What is ‘Callback’ in node.js?
A : Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.
Q22 : What are the pros and cons of Node.js?
A : Pros:
a) If your application does not have any CPU intensive computation, you can build it in Javascript top to bottom, even down to the database level if you use JSON storage object DB like MongoDB.
b) Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather than a single page application or a websockets app run on top of Node.js.
Cons:
a) Any intensive CPU computation will block node.js responsiveness, so a threaded platform is a better approach.
b) Using relational database with Node.js is considered less favourable.
Q23 : What is control flow function?
A : A generic piece of code which runs in between several asynchronous function calls is known as control flow function.
Q24 : Where can we use node.js?
A : Node.js can be used for the following purposes
a) Web applications ( especially real-time web apps )
b) Network applications
c) Distributed systems
d) General purpose applications.
Q25 : How node.js works?
A : Node.js works on a v8 environment, it is a virtual machine that utilizes JavaScript as its scripting language and achieves high output via non-blocking I/O and single threaded event loop.