1. What is Node.js?
Node.js is a JavaScript engine used for executing JavaScript code outside the browser. It is normally used to build the backend of the application and is highly scalable.
2. What is the difference between Node.js and JavaScript?
JavaScript is a scripting language whereas Node.js is an engine that provides the runtime environment to run JavaScript code.
- JavaScript: It is a light-weighted programming language (“scripting language”) used to develop interactive web pages. It can insert dynamic text into the HTML elements. JavaScript is also known as the browser’s language.
- Node.js: It is used to run JavaScript programs outside the browser and it mostly runs server-side code. It cannot be used to run HTML tags.
3. Is Node.js single-threaded?
Yes, Node.js is a single-threaded application as it is built using the single-threaded event loop model architecture.
4. What kind of API function is supported by Node.js?
There are two types of API functions supported by Node.js:
- Synchronous: These API functions are used for blocking code.
- Asynchronous: These API functions are used for non-blocking code.
5. What is the difference between Synchronous and Asynchronous functions?
- Synchronous function: These are the function that block the execution of the program whenever an operation is performed. Hence these are also called blocking operations. We use these functions to perform lightweight tasks
- Asynchronous function: These are the operations that do not block the execution of the program and each command is executed after the previous command even if the previous command has not computed the result. We use these functions to perform heavy tasks.
6. What is a module in Node.js?
In Node.js Application, a Module can be considered as a block of code that provide a simple or complex functionality that can communicate with external application. Modules can be organized in a single file or a collection of multiple files/folders. Modules are useful because of their reusability and ability to reduce the complexity of code into smaller pieces. Some examples of modules are. http, fs, os, path, etc.
7. What is npm and its advantages?
NPM stands for Node Package Manager. It is an online repository for Node.js packages. We can install these packages in our projects/applications using the command line.
8.What is middleware?
Middleware is the function that works between the request and the response cycle. Middleware gets executed after the server receives the request and before the controller sends the response.
9.How does Node.js handle concurrency even after being single-threaded?
Node.js internally uses libuv library for handling all async call. This library creates multiple thread pools to handle async operations.
10. What is control flow in Node.js?
Control Flow functions are executed whenever there is an async call made in the program. These functions define the order in which these asynchronous functions will be executed.
11. What do you mean by event loop in Node.js?
Event Loop in Node.js is used to handle callbacks. It is helpful in performing non-blocking I/O operations. An event loop is an endless loop, which waits for tasks, executes them, and then sleeps until it receives more tasks.
12. What is the order in which control flow statements get executed?
The order in which the statements are executed is as follows:
- Execution and queue handling
- Collection of data and storing it
- Handling concurrency
- Executing the next lines of code
13. What are the main disadvantages of Node.js?
Since Node.js is single-threaded so multi-threaded engines are better and can handle tasks more efficiently. Also, we do not use relational databases with Node.js like MySQL mostly non-relational databases like MongoDB is used.
14. What is REPL in Node.js?
REPL in Node.js stands for Read, Evaluate, Print, and Loop. It is a computer environment similar to the shell which is useful for writing and debugging code as it executes the code in on go.
15. How to import a module in Node.js?
We use the require module to import the External libraries in Node.js. The result returned by require() is stored in a variable which is used to invoke the functions using the dot notation.
16. What is the difference between Node.js and AJAX?
Node.js is a JavaScript runtime environment that runs on the server side whereas AJAX is a client-side programming language that runs on the browser.
17. What is package.json in Node.js?
package.json is a file that is used to store the metadata of all the contents of the project. It is used to describe the module used, run commands, and other useful information about the project.
18. How to write hello world using node.js?
| const http = require(‘http’);
// Create a server object http.createServer(function (req, res) { res.write(‘Hello World!’); res.end(); }).listen(3000); |
Run this program from the command line and see the output in the browser window. This program prints Hello World on the browser when the browser sends a request through http://localhost:3000/.
What is the most popular Node.js framework used these days?
The most famous Node.js framework used is Express.js as it is highly scalable, efficient, and requires very few lines of code to create an application.
What are promises in Node.js?
A promise is basically an advancement of callbacks in NodeJS. In other words, a promise is a JavaScript object which is used to handle all the asynchronous data operations. While developing an application you may encounter that you are using a lot of nested callback functions which causes a problem of callback hell. Promises solve this problem of callback hell.
1) What is NodeJS?
Node.js can be simply explained as it is a concept of two outcomes: runtime environment and JavaScript library. So basically, node.js will enable you to use javascript beyond the browser. It can make Javascript like ‘go anywhere Javascript’.
2) What is NPM?
Javascript operates in a runtime environment with the help of node js having its own package manager, this package manager is called NPM.
3) What is CLI in Node.js?
One of the vital reasons for Node.js getting popular is its 900000 packages connected to a large ecosystem. CLI is a command-line interface that will allow you to automate your tasks by taking advantage of this vast ecosystem. Not only that, by writing CLI you can differentiate your proposed packages among the ecosystem.
4) In which Language Node Js is written?
Node.js shows compatibility with three types of language
- C
- C++
- Javascript
5) Who is the author of Node Js?
Ryan Dahl is the author of Node.js it was almost 13 years back when the javascript environment was introduced to the world. Initially, Node is was supported by Linux and Mac OS X but later it was sponsored by Joyent.
6) What is a Javascript Engine?
Javascript engine is used to run the java code in the browser so you can define a javascript engine as a computer program that is used to perform the java code. Initially, it was just used for interpretation and progressively it improved and got evolved. Generally, all browsers have one dealer and he is the one who develops the javascript engine.
7) What is a V8 Engine?
In 2008 when google chrome was launched time chrome also introduced its project of the V8 engine. It is an open-source network that can be written in the c++ language.
8) What is ECMAScript?
Ecmascript first appeared in 1997, which was specified and developed by Esma internationals. Evmascriot is also a programming language, which developed various other scripts like Jscript, ActionScript, and the most popularly used javascript.
9) How can you check the installed version of Node Js?
For that, you need to install NPM which is a package manager. The second thing you will need is to have a node in your computer, you can check installed NPM and node by just typing simple commands. Now carry the following steps
- Open the windows command prompt
- Open command-line tool line Babun, Powershell, ConEmu, etc.
- Type node-v which will display your current version of Node Js.
10) What are Modules in Node Js?
Modulus is various commands used in node js to perform tasks like addition, subtraction, division, multiplication, etc. Ins short you can do maths in js using modulus.
11) What are the common Modules?
Arithmetic operations ( addition, subtraction, multiplication, division), exponentials, increment, and decrement are various common modulus in js.
12) What require() is used in Node Js?
Modulus is operated by two main managing modules
- The Require module
- The module module
Both of them are available on a global scope.
13) What the module. exports in Node Js?
The module. exports is a default application that can be found in every js file of Node js.
14) Is Node Js Single-threaded?
Node Js is single-threaded but it is non-blocking as well, it means that while operating node js various functions like callbacks is carried out in the background which is carried out using different threads or multiple threads.
15) Node JS Vs Ruby
| Feature | Node JS | Ruby On Rails |
| Written In | C, C++, JavaScript | Ruby |
| Operating System | Solaris, OpenBSD, FreeBSD, Linux, Mac, MS, webOS and nonstops | Cross-Platform |
| Type | Event-driven networking | Web application framework |
| License | MIT | MIT |
| Performance | High | Low |
| Popularity | Popular for its features | Yet to be popular |
| Documentation | Available | Lack of documentation |
| Consistency | Inconsistent | Consistent structure |
| Complexity | Easy to implement | Complex implementation |
16) What are the events?
- The event can be explained as activities carried out. For example, when you open a file it is an event when you close a file it is an event.
- In Node js, there is a defaulted module named “Events” with which you can carry various activities like create, fire, listen, etc.
17) What the event loop in Node Js?
Non-blocking operations in Node Js are carried out with the help of the event loop.
18) How to create a simple server in Node js that returns Hello World?
Certain steps are needed to be carried out for this operation:
- Import the module which is required.
- Create the server using HTTP.createServer().
- Test the request and wait for a response
19) Difference between the cluster and child_process modules?
- A cluster is when one master program is running two or more nodes at a single running time.
- A child process simply starts a new script on the system, it is quite similar to the cluster but in a different language.
20) How to stop the master process without suspending all of its child processes?
Upstart is a process management system with which you can stop the master process. Generally when the master process is stopped or killed the child process still continues to work.
21) What does an emitter do and what is a dispatcher?
The emitter is one that makes communication between two nodes.
When the job of the scheduler is completed in a program then dispatched comes into the frame and takes the task to the desired status.
22) Since the node is a single-threaded process, how to make use of all CPUs?
The node js is single-threaded but the node name itself suggests that it is a topology, which means there is communication between two nodes. This communication between the two nodes makes use of all CPUs.
23) Syntax to install modules using NPM.
Syntax : $ npm install
Example:
$ npm install express
var express = (‘express’);
Where express is the Name of the module,
express is a JS file, that can be used in your module.
24) Mention types of npm modules available that are used very often.
Express, connect, socket.io and SockeJS, pug, MongoDB and Mongojs, Redis, Lodash, forever, bluebird, moment are some of the npm modules.
25) Command to list modules installed in current npm
$ npm ls
Note: Remember not to mention npm in UPPERCASE – (Recommended)
26) What are the attributes of package.json
Name, version, description, homepage, author, contributors, dependencies − list of dependencies, repository − repository type and URL of the package, the main − entry point of the package, keywords.
27) What is REPL?
REPL – Read, Eval, Print, Loop.
It is an environment for input commands to perform REPL tasks. Each of the tasks is associated with its respective operations.
28) What kind of applications can be built by Node.JS.
DIRT, JSON, I/O Bound, Single Page applications are preferable to use Node.JS.
29) What is the latest version of NodeJS?
Node v16.3.0 is the current version.
30) NodeJS is a framework. True or False.
False. It is runtime or environment, but not a framework.
31) Commands to work with the file from the local database.
Var fs = require(‘fs’); Read: fs.readFile();Create:fs.appendFile();fs.open();fs.writeFile();Write: fs. writeFile();Delete: fs.unlink();Rename: fs.rename();Update:fs.appendFile()fs.writeFile()
32) What is an error-first callback in Node JS?
In order to check for the proper working of the code, we need to verify error-free execution. In this regard, error-first callbacks are used, which will send error first, followed by related data to the error.
33) What is the cluster?
Cluster is a process to handle thread execution load while working with multi-core systems.
34) Why node is single-threaded?
In order to upgrade the performance well, single thread operations work better than multi-threaded operations.
35) How does the URL module work?
This module helps URL to parse it into host, pathname, search, query, etc.
Example:
var url = require(‘url’);var adr = ‘https://mindmajix.com/?s=node+js+training’;var q = url.parse(adr, true);console.log(q.host); //returns ‘mindmajix.com’console.log(q.search); //returns ‘?s=node+js+training’
36) What is the use of the Nodemailer module.
It is not included in the default modules list, it has to be installed using npm.
Var nodemailer = require(‘nodemailer’);
37) What are the types of versions available?
Patch_Version, Minor_Version, Major_Version.
38) What are event emitters in NodeJS?
Objects in NodeJS will have to trigger events in order to maintain the asynchronous execution of the core API used. These objects that emit events are known as Event Emitters.
39) What are event listeners?
Events that are emitted by event emitters have to listen in order to continue the asynchronous execution of the threads. These objects that listen to the emitted events are known as listeners.