Node Interview
Node Interview
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.
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:
request, or completing some other task that could block the code thread for a
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
fulfilled, rejected, or pending. Promise users can attach callbacks to handle the
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
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
● pathTo handle file paths
● punycodeDeprecated. 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_decoderTo 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
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) {}
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.
the project
storage
● public/ — contains all static files like images, styles and javascript
routes
1. Authentications
2. Error Handling
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
Streams are pipelines that read or write data from a source and
of streams:
● Readable
● Writable
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.