DEV Community

Johnathon roy
Johnathon roy

Posted on

Interview Questions on Node.js

Here we listed down the most asked interview questions on Node js so that you don’t have to go anywhere. This is a one-stop destination for all your queries. We provide you with the top 25 interview questions on Node js so you can ace your interview. Let’s just look at the questions below.

What is node.js?

The first and most asked question is what is Node js?. Node js is an open-source server environment that uses javascript to make web software that is computationally simple but is easily accessed. It works really fast and can run on different platforms like Windows, Linux, Mac OsX, etc

What are some key benefits to Nodejs?

There are numerous benefits of Node js which are explained as follows.

It is fast because it is built on Google chrome’s V8 JavaScript engine which makes it really fast.
Node js has no buffering and no blocking while working. It output the data in chunks.
It is Asynchronous meaning Nodejs never stops for an API to return the data. It is ready to take the next request.

Is Node js single-threaded? If yes, then why?

Well yes and actually no. NodeJS is single-threaded since no two functions can be run at the same time. Although, a running program called a process can have multiple threads. NodeJS runs only one program at a time to implement its asynchronous nature of program execution hence a single-threaded server environment but can a program can use multiple threads internally to yield optimal performance hence a multi-threaded server environment.

What type of applications you can build using Node js?

Streaming apps
Chat applications
Internet of things
Microservices
Collaboration tools
You just name it and we can build it using Node.js

How the content of a file is read by Node js?

The NodeJS’s fs (file-system) module provides an API to interact with the system files. The files can be read with multiple methods available to us. In the example below, we will be using the readfile method of fs module to read the contents of a file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var fs = require(‘fs’);

fs.readFile(‘DATA’, ‘utf8’, function(err, contents) {

console.log(contents);

});

console.log(‘after calling readFile’);

if you want to know in synchronous manner then have a look in this sample

var fs = require(‘fs’);

var contents = fs.readFileSync(‘DATA’, ‘utf8’);

console.log(contents);

Discuss the streams in Nodejs? And what are the different types of streams? Streams are something that allows the reading and writing of data from source to destination in a continuous process.

Streams are of 4 types

· that promotes reading operation

· that promotes writing operation

· that promotes above both

· < Transform> is a kind of duplex stream which does the computation based on available input.

What is closure?

A closure is a function that is sustained in another scope that has access to all other variables in the outer scope.

Does Zlib use in Nodejs? If yes, then why?

Yes, Zlib used in Nodejs and Zlib was written by Jean-loup Gailly and Mark Adler. It is a cross-platform data compression library. You need to install a node- Zlib package in order to use Zlib in Nodejs. A sample is given below which shows the code to use Zlib.

ALSO READ What is an API as well as How Does It Work?
1
2
3
4
5
6
7
8
9
var Buffer = require(‘buffer’).Buffer;

var zlib = require(‘zlib’);

var input = new Buffer(‘lorem ipsum dolor sit amet’);

var compressed = zlib.deflate(input);

var output = zlib.inflate(compressed);

Discuss the globals in Node.js?

Globals basically comprise three words which are Global, Process and Buffer. Let’s discuss it one by one.

Global– As the name is suggesting Global is something which has many things under its umbrella. So it’s a namespace object and act as an umbrella for all other objects < global>

Process– It is a specified type of Global and can convert Asynchronous function into an Async callback. It can be linked from anywhere in the code and it basically gives back the information about the application.

Buffer– Buffer is something that is known as a class in Nodejs to tackle the binary data.

Differentiate between Nodejs and Ajax?

Ajax is used on a specific section of a page’s content and update that specific portion rather than updating the full part of the content.

Nodejs, on the other hand, used for developing client-server applications. Both of the above serve different purposes and these are the upgraded implementation of JavaScript.

What is Modulus in Node Js?

Modules are a reusable block of code whose existence doesn’t impact alternative code in any means. it’s not supported by Javascript. Modules come in ES6. Modules are necessary for Maintainability, Reusability, and Namespacing of Code.

to know about some more crucial questions- https://codersera.com/blog/25-interview-questions-on-node-js/

Top comments (2)

Collapse
 
khrisl33t profile image
kHRISl33t

Would never ask anyone about a specific library, even if it's a system module. I would rather ask someone about event-loop, callbacks, promises, async/await, memory management, how to write a callback to promise, what is a callback hell and how you can fix it, etc..

These are missing from this post which I think are better interview questions, but I see you mentioned some of them in the linked article.

Collapse
 
bogadrian profile image
Bogdan Adrian

Yeah, that’s for sure. Event loop question is a must when talking about Node.