0% found this document useful (0 votes)
18 views10 pages

Node Interview

Uploaded by

arunv1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

Node Interview

Uploaded by

arunv1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Intro:

1.​ Hi my self Arun Working in kc techservices HAVE 3+ years EXPIRE as mean stack
developer
Work Expirence:
1.​ Currently working with Health care project its just electronic medical report
Application
2.​ Also worked with some Iot project where we develop a products for old age people.

Role and Responsibility:


Designed and wrote project configurations, tasks and loading plugins, etc. with gulp and
NPM
Customized server JSON response and reduce noise based on
RESTful API calls

Deployed Node.JS apps


Deployment: CI CD
We build an docker image and we
in aws
For version control we use Git repository

Node :
Javascript framework
Develop on v8 eng
Compile js to mchinecode
Used for webapp
Suit for realtime app

Benefit Node
Highly Scalable
Simple and fast
Opensource
Single thread
Cross platform
Singlethread non blocking event loop[
Singlethread async process with acync application musht scalpel
Thread based implementation
Api Function that can be create in Node js:
Asynchronous non blocking
Synchronous blocking
Asynchronous and non blocking:

Package is heart of njs

Node shell /REPL


read the user input convert js data structure store in memory
Eaval the structure

Error first callback:


Callbacks

A callback function is usually used as a parameter to another function. The

function that receives the callback function as a parameter

is normally fetching data from a database, downloading a file, making an API

request, or completing some other task that could block the code thread for a

notable amount of time.

What is a Promise?

A promise is an object that may produce a single value some time in the

future: either a resolved value, or a reason that it’s not resolved (e.g., a

network error occurred). A promise may be in one of 3 possible states:

fulfilled, rejected, or pending. Promise users can attach callbacks to handle the

fulfilled value or the reason for rejection.

Promises are eager, meaning that a promise will start doing whatever task you

give it as soon as the promise constructor is invoked. If you need lazy, check

out observables or tasks.

Asynchronous programming is a means of parallel programming in which a unit

of work runs separately from the main application thread and notifies the calling
thread of its completion, failure or progress. You may be wondering when you should

use asynchronous programming and what are its benefits and problem points

Built In Module:

●​ assert​
●​ buffer​
●​ child_process​ To run a child process
●​ cluster​ To split a single Node process into multiple
processes
●​ crypto​ To handle OpenSSL cryptographic functions
●​ dgram​ Provides implementation of UDP datagram
sockets
●​ dns​ To do DNS lookups and name resolution functions
●​ domain​ Deprecated. To handle unhandled errors
●​ events​ To handle events
●​ fs​ To handle the file system
●​ http​ To make Node.js act as an HTTP server
●​ https​ To make Node.js act as an HTTPS server.
●​ net​ To create servers and clients
●​ os​ Provides information about the operation system
●​ path​To handle file paths
●​ punycode​Deprecated. A character encoding scheme
●​ querystring​ To handle URL query strings
●​ readline​ To handle readable streams one line at the time
●​ stream​ To handle streaming data
●​ string_decoder​To decode buffer objects into strings
●​ timers​ To execute a function after a given number of
milliseconds
●​ tls​ To implement TLS and SSL protocols
●​ tty​ Provides classes used by a text terminal
●​ url​ To parse URL strings
●​ util​ To access utility functions
●​ v8​ To access information about V8 (the JavaScript
engine)
●​ vm​ To compile JavaScript code in a virtual machine
●​ zlib​ To compress or decompress files
Module load
Require or using di
Require:
require are used to consume modules.
Module exports
are the instruction that tells Node. js which bits of code (functions, objects, strings,
etc.) to “export” from a given file so other files are allowed to access the exported
code

Every action on a computer is an event. Like when a connection is made or a


file is opened.

Objects in Node.js can fire events, like the readStream object fires events
when opening and closing a file:

Events Module
addListener(eventName, fn) {}
on(eventName, fn) {}

removeListener(eventName, fn) {}
off(eventName, fn) {}

once(eventName, fn) {}

emit(eventName, ...args) { }

listenerCount(eventName) {}

rawListeners(eventName) {}

control flow function?


A generic piece of code which runs in between several asynchronous
function calls is known as control flow function.

1.​ Firstly, the order of execution must be controlled.


2.​ Then, the required data need to be collected.
3.​ Next, the concurrency must be limited.
4.​ Once done, the next step of the program has to be invoked.

. List down the two arguments that async.queue takes as input?


Below are the two arguments that async.queue takes as input:

1.​ Task Function


2.​ Concurrency Value
NODE EVENT LOOP

EXPRESS
The var app = express() statement creates a new express
application for you. The createApplication function from the
lib/express.js file is the default export, which we see as the
express() function call.

Node and Express don’t come with a strict file and folder structure.
●​ controllers/ — defines your app routes and their logic. You main

route might be index.js but you might also have a route called for

example ‘/user’ so you might want to make a JS file that just handles

that.

●​ helpers/ — code and functionality to be shared by different parts of

the project

●​ middlewares/ — Express middlewares which process the incoming

requests before handling them down to the routes

●​ models/ — represents data, implements business logic and handles

storage

●​ public/ — contains all static files like images, styles and javascript

●​ views/ — provides templates which are rendered and served by your

routes

●​ tests/ — tests everything which is in the other folders

●​ app.js — initializes the app and glues everything together

●​ package.json — remembers all packages that your app depends on

and their versions

Explain the purpose of module.exports?


A module in Node.js is used to encapsulate all the related codes into a single unit of
code which can be interpreted by shifting all related functions into a single file. For
example, suppose you have a file called greet.js that contains the two functions as
shown below:

security implementations within Node.js?


Major security implementations in Node.js are:

1.​ Authentications
2.​ Error Handling

Libuv is a multi-platform support library of Node.js which majorly is used for


asynchronous I/O.

SPAWN

In Node.js, the spawn() is used to launch a new process with the provided set of
commands. This method doesn’t create a new V8 instance and just one copy of the
node module is active on the processor. When your child process returns a large
amount of data to the Node you can invoke this method.

Syntax:

1
child_process.spawn(command[, args][, options])

Whereas, the fork() in Node.js is a special instance of spawn() that executes a new
instance of the V8 engine. This method simply means that multiple workers are
running on a single Node code base for various task

child_process.fork(modulePath[, args][, options

Explain the concept of stub in Node.js.


In Node.js, stubs are basically the programs or functions that are used for stimulating
the module or component behavior. During any test cases, stubs provide the canned
answers of the functions.

D/between process.nextTick() and setImmediate()?


In Node.js, process.nextTick() and setImmediate(), both are functions of the Timers
module which help in executing the code after a predefined period of time. But these
functions differ in their execution. The process.nextTick function waits for the
execution of action till the next pass around in the event loop or once the event loop
is completed only then it will invoke the callback function. On the other hand,
setImmediate() is used to execute a callback method on the next cycle of the event
loop which eventually returns it to the event loop in order to execute the I/O
operations.

What are Node Streams?

Streams are pipelines that read or write data from a source and

transfer it to a continuous flow destination. There are four types

of streams:

●​ Readable

●​ Writable

●​ Duplex (both readable and writable)

●​ Transform (A type of duplex stream. Its output is

calculated using the input)

Worker thread

is a continuous parallel thread that runs and accepts messages until the time
it is explicitly closed or terminated.
Empty array
1||0
‘’|”arun”
setTmeout
Setinteralval print 1 to 10 with 1 sec delay
Promises resolve sequenc -arrqy for loop
promise. all will not execute neither in parallel or sequentially but concurrently.

You might also like