0% found this document useful (0 votes)
14 views13 pages

Node JS Ai Kit

The document provides an overview of Node.js, covering key concepts such as nonblocking I/O, server creation, CRUD operations, authentication vs authorization, and the use of NPM. It explains various frameworks like Express.js, REST APIs, and important HTTP methods, as well as how to manage dependencies and create APIs. Additionally, it discusses middleware functions, event handling, and the architecture of Node.js applications.

Uploaded by

kushalthadi143
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)
14 views13 pages

Node JS Ai Kit

The document provides an overview of Node.js, covering key concepts such as nonblocking I/O, server creation, CRUD operations, authentication vs authorization, and the use of NPM. It explains various frameworks like Express.js, REST APIs, and important HTTP methods, as well as how to manage dependencies and create APIs. Additionally, it discusses middleware functions, event handling, and the architecture of Node.js applications.

Uploaded by

kushalthadi143
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/ 13

NODE_JS_AI_KIT

27 September 2023 20:51

What is nonblocking I/O in node?

Nonblocking I/O in Node JS enables concurrent task execution,


preventing application blocking during file reading or database querying.
This enhances performance and scalability by allowing other tasks to
continue while waiting for I/O operations.

Why is the use of Node JS?

Node JS enables server-side execution of JavaScript and offers


scalability, high performance, and the ability to handle large concurrent
requests. It has a wide range of modules and packages, making it
suitable for building web applications and APIs.

What is an API?

An API is a software intermediary that allows two applications to talk to


each other. For example, OLA, and UBER use Google Maps API to
provide their services.

How to create a server?

To create a server using Node JS and Express, 1. First, Import the


Express module. 2. Create an Express application. 3. Make the server
listen on port 3000. This establishes a server that can handle incoming
requests on port 3000.

What is CRUD?

CRUD in Node JS refers to the basic operations of Create, Read,


Update, and Delete. It involves creating data with a POST request,
reading data with a GET request, updating data with PUT or PATCH
requests, and deleting data with a DELETE request.

What is the difference between authentication and authorization?

Authentication verifies user identity using username and password.


Authorization controls access rights and permissions. Authentication
confirms identity, while authorization grants or denies access based on
authenticated identity.

What is NPM?

New Section 5 Page 1


What is NPM?

NPM is the package manager for the Node JS packages. It provides a


command line tool that allows you to publish, discover, install, and
develop node programs.

What is Node JS?

Node JS is an open-source runtime environment that allows you to run


JavaScript code on the server side. It is efficient for building scalable
and high-performance applications. Node JS is commonly used for
building web servers, APIs, and real-time applications.

What is Express JS?

It is a free and open-source, server-side Web Application Framework for


Node JS. It provides a robust set of features to build web and mobile
applications quickly and easily.

What is REST API?

REST stands for Representational State Transfer. It is a set of principles


that define how Web standards, such as HTTP and URLs, are supposed
to be used.

Explain inbuilt node packages?

Node JS comes with several built-in packages. Some of the commonly


used built-in packages in Node JS include: 'fs', 'http', 'path', 'events', etc.

What are server-side web applications?

Server-side web applications are applications where the processing and


rendering of web pages happen on the server. The server generates the
HTML content and sends it to the client's browser for display. Examples
of server-side web application frameworks include Node JS, Python, …

On which engine does Node JS run?

Node JS runs on the V8 JavaScript engine, which is developed by


Google.

Explain any five packages of NPM.

New Section 5 Page 2


Express: A web app framework. Jsonwebtoken: Generates/verifies
JWTs for authentication and secure data transmission. SQLite: A
lightweight serverless relational database engine. Bcrypt: Provides
encryption, comparison, etc. Sqlite3: Interacts with SQLite databases.

What are the applications of Node JS?

Node JS is utilized for building scalable APIs, real-time apps, web


applications, serverless computing, microservices, and automation.

What is the main HTTP request methods?

The GET method to retrieve data from server without changes actual
data. The POST method to send new data for server. The PUT method
to update, replacing existing server data. The DELETE method to
remove data from the server. The PATCH method to partly update data,
altering specific attributes.

What are Path Parameters and Query Parameters?

Path parameters are part of the URL path. They are used to identify a
specific resource. Query parameters are appended to the URL and are
separated using a question mark. These parameters come after the path
of the URL and allow clients to send additional information to the server.

What is the purpose of the PUT method?

The "PUT" method in HTTP is designed to update existing resources on


a server and it will not make any new changes or create new data no
matter how many times you send the same PUT request to the server.

Explain the post() method in Node JS.

The post() method in Node JS is used to send HTTP POST requests to


a specified URL. It allows you to send data to the server in the request
body.

What is the purpose of module.exports?

module.exports enables exporting functions, objects, or values for use in


other modules. This promotes code reusability, modularity, and
maintainability in Node JS applications.

What are URL, and API methods in Node JS?


New Section 5 Page 3
What are URL, and API methods in Node JS?

In Node JS, URLs access web resources. The URL module resolves
and parses URLs. API methods in Node JS interact with APIs,
performing CRUD operations (GET, POST, PUT, DELETE) on exposed
resources.

What is the difference between Express JS and Node JS?

Node JS is a JavaScript runtime environment that executes JavaScript


code outside a web browser. While Express JS is a free and open-
source Server-side Web Application Framework for Node JS. It provides
features and tools for building web applications using Node JS.

What are Modules and their Methods in Express JS?

In Express JS, modules are reusable code pieces used for structuring
the application, while methods are functions within modules that perform
specific tasks. For example, the 'app' module handles HTTP requests,
and the 'app.get()' method handles the get API.

What is the use of require() function?

The `require()` function in Node JS imports external modules or files and


assigns their exported content to a variable, allowing you to use their
functionality in your application.

What is the use of terminal (REPL), in Node JS?

The Node JS REPL (Read-Eval-Print Loop) is an interactive shell used


for real-time code testing, debugging, and experimenting without
creating separate script files, aiding in code evaluation and
development.

What are Route paths in web applications, in combination with request


methods and define the specific endpoints where requests can be
made?

Route paths are URL patterns used in web applications to define the
endpoints at which requests can be made. They are combined with the
request methods app.METHOD(PATH, HANDLER) to specify the
actions to be performed on those endpoints.

How to retrieve the body of a query?

New Section 5 Page 4


To retrieve the body of a query in Node JS, you can use express.json()
middleware to recognize the incoming request object as JSON and
parse it. After that, you can access the HTTP request body using
request.body.

What is the middleware function?

Middleware is a special function in Express JS that handles requests


from the user or previous middleware. It processes the request and can
either pass it to another middleware, call the API Handler, or send a
response to the user.

Is node a single threaded application?

Yes, Node JS is mainly single-threaded. But it uses an event-driven,


non-blocking I/O model to handle multiple requests at the same time,
making it efficient for high-performance and scalable applications.

How to connect a database in NodeJS?

To connect a database in NodeJS, We can use `sqlite` and `sqlite3`


node packages to connect SQLite Database from Node JS.

Explain Express js architecture.

Express.js has a simple and minimalist architecture. It allows developers


to build web applications in a structured manner by using modular
routes and middleware functions. It provides flexibility in handling HTTP
requests and processing responses.

How to print Hello World in Node JS?

To print "Hello World" in Node.js, write console.log("Hello World"); in a


JavaScript file and run it using node filename.js in the terminal.

What is package.json?

package.json is a file in NodeJS projects that holds important project


details like name, version, description, and dependencies. It helps
package managers (npm or yarn) manage dependencies and scripts,
simplifying project sharing and collaboration.

What is the function of listen in Express?

New Section 5 Page 5


What is the function of listen in Express?

In Express, the "listen" method is used to bind and listen for connections
on the specified port. Essentially, it starts up the server and allows it to
begin accepting requests from clients.

What is the use of 'express.json()' in your Node.js project?

The 'express.json()' is used to recognize the incoming request object as


a JSON object and parse it, allowing you to work with it as a JavaScript
object.

What is Nodemon?

The Nodemon is a tool that restarts the server automatically whenever


we make changes in the Node JS application.

What is Bcrypt and what are the uses, and methods of Bcrypt?

Bcrypt is a library used for secure password hashing in NodeJS. It helps


in storing passwords safely in databases. Bcrypt provides methods like
'hash' to create a hashed password and 'compare' to check if a
password matches the stored hash.

How to install node?

To install Node JS, visit the official Node JS website (nodejs.org) and
download the appropriate installer for your operating system. Run the
installer and follow the prompts to complete the installation. Once
installed, you can verify the installation by opening a terminal and typing
"node -v" to check the installed version.

Explain about Node JS and how to create APIs?

Node JS is a JavaScript runtime that executes JavaScript code outside


of a browser. To create APIs, use Express.js. Install it with npm, create
an app, define routes using HTTP methods like GET and POST, and
specify responses. Start the server with app.listen() and a port number
to handle requests.

What is npm and why do we use it?

NPM is the package manager for the Node JS packages with more than
one million packages. It provides a command line tool that allows you to
publish, discover, install, and develop node programs. It is used to
install, manage, and share reusable code modules (packages) in your
projects.

New Section 5 Page 6


What are the applications of Node JS?

Node JS is used to build scalable, high-performance applications. Some


common applications are real-time chat, API servers for single-page
apps, data streaming, and server-side rendering. Examples include
Socket.IO for real-time chat, Express.js for API servers, Node JS
streams for data streaming, and Next.js for server-side rendering.

What is the difference between javascript and nodejs?

JavaScript is a client-side programming language for web browsers,


while Node JS is a server-side runtime environment for JavaScript,
which offers additional features like file system access and networking.

How does Node JS work?

Node JS is a JavaScript runtime environment that executes JavaScript


code outside a web browser.

What is app.get()?

In Express.js, app.get() defines a route handler for handling HTTP GET


requests. It takes a route path and a callback function that processes
the request and sends a response.

How to expose node JS modules?

Node JS modules can be exposed using the `module.exports` or


`exports` keywords. They allow us to make functions, objects, or
variables available for use in other files.

Which command is used to install Node JS express module?

To install the Express module in Node JS, use the following command:
`npm install express`. This command installs the Express package from
the npm registry and adds it to your project's dependencies.

Which module is required to create a web server?

Express module is needed to create a web server in NodeJS.

What are the dependencies in Node JS?

Dependencies in Node JS are external modules or packages that your


New Section 5 Page 7
Dependencies in Node JS are external modules or packages that your
application relies on to perform certain tasks. They are specified in the
"package.json" file and can be installed using a package manager like
npm. Dependencies are essential components for adding functionality or
integrating third-party libraries into your Node JS application.

What is jwt verify?

jwt.verify() verifies jwtToken and if it’s valid, returns payload. Else, it


throws an error.

How to parse a JSON response?

To parse a JSON response, you can use the built-in JSON.parse()


method.

Is the server implemented using Node.js?

Yes, the server is implemented using Node.js.

What is an HTTP request?

An HTTP request is a client message to a server for asking for data


retrieval. It includes a method (GET, POST), URL, HTTP version,
headers, and an optional message body within the HTTP request.

How to create an entire backend architecture with bcrypt and jwt (Simple
login system) and what happens behind the scenes?

To create the backend architecture: 1. Set up a NodeJS server with


Express. 2. Install bcrypt and jsonwebtoken. 3. Create registration and
login routes. 4. Hash passwords with bcrypt. 5. Compare passwords
during login. 6. Create and send a JWT token for authentication.

What is a patch()?

patch() is an HTTP method used to partially update a resource. In Node


JS with Express.js, it defines a route for handling PATCH requests,
efficiently updating specific fields without affecting the entire resource.

What are valid forms of route path?

Valid forms of route paths in Express.js can include static paths,


dynamic paths with parameters, optional parameters, and route patterns
using regular expressions. Some examples of valid route paths are
'/users', '/users/:id', etc

New Section 5 Page 8


'/users', '/users/:id', etc

What are the timing features of Node JS?

Node JS has three timing features: setTimeout, setInterval, and


setImmediate. - setTimeout schedules a function to run after a specified
delay. - setInterval repeatedly runs a function at specified intervals. -
setImmediate executes a function immediately after current event loop
cycle. These help in managing asynchronous tasks, controlling the flow
of an application.

How to use process.nextTick() and setImmediate() and what is the


difference between them?

In Node JS, process.nextTick() and setImmediate() are used to


schedule asynchronous tasks. The main difference is that
process.nextTick() executes in the current event loop iteration, while
setImmediate() executes in the next iteration.

What is CORS?

CORS (Cross-Origin Resource Sharing) is a security mechanism that


allows web applications running on one domain to request resources
from another domain. It ensures that requests from different origins are
controlled, preventing unauthorized access and protecting user data.

What will happen if the call stack and the event loop are empty in Node?

When both the call stack and event loop are empty in Node JS, the
process will terminate unless there are active timers or ongoing I/O
operations.

What is fork in nodejs?

In Node JS, the fork() method creates child processes that run
independently from the main application. This enables parallel execution
and improved resource usage. Child processes can communicate with
the parent process through inter-process communication (IPC).

What else can be used instead of express for handling requests?

Other frameworks like Koa, Hapi, Fastify, or Sails.js can replace


Express for handling requests in Node JS, offering various features and
performance optimizations to suit different project needs.

What are Node JS buffers?

New Section 5 Page 9


What are Node JS buffers?

Node JS buffers are temporary storage areas used to handle binary


data. They store raw binary data in a fixed-size memory chunk. Buffers,
created with the Buffer class, allow operations such as concatenation,
slicing, and reading/writing values at specific positions.

What is the specific method in the Node Redis driver that should be
used to automatically execute a set of commands without manual
intervention?

To execute a set of commands automatically using the Node Redis


driver, you can use the `multi()` method of the client object. This method
allows you to queue multiple commands and execute them atomically as
a single operation using the `exec()` method.

Where to find the implementation of the set timeout function in Node


JS?

In Node JS, you can find the implementation of the setTimeout function
in the 'timers' module. It allows you to schedule a one-time execution of
a function after a specified delay. The 'timers' module can be accessed
globally or by requiring it in your code.

How to export in Node JS?

In Node JS, you can export functions, objects, or values by assigning


them to properties of "module.exports" or "exports". This allows other
modules to import and use them.

Which class is used to create and consume custom events in Node JS?

To create and consume custom events in Node JS, developers use the
EventEmitter class. It is a built-in module that implements the observer
pattern, enabling the definition of custom events and attachment of
event listeners for handling them, adding event-driven functionality to
Node JS applications.

What is fs module in Node JS?

fs module in Node JS is built-in and enables file system operations on


the server-side. It facilitates tasks like reading, writing, modifying,
creating, deleting, and updating files and directories.

How to create and consume custom event in node JS?

New Section 5 Page 10


How to create and consume custom event in node JS?

To create and consume custom events in Node JS, import the 'events'
module, create an event emitter instance, define the event with 'on', and
trigger it with 'emit'.

How will we take query parameters?

To take query parameters in Express.js, you can use the req.query


object. Query parameters are included in the URL after the ? symbol.
For instance, in the URL /users?id=123&name=John, you can access
the id and name parameters using req.query.id and req.query.name
respectively.

How to create a Node JS CLI application?

To create a Node JS CLI application that takes user input and provides
a response, you can use `process.argv` to access the command-line
arguments. Implement logic based on the input and attribute to generate
and display the desired response.

How to parse the Node JS JSON Object?

To parse a JSON object in NodeJS, you can use the JSON.parse()


method. This method takes a JSON string as input and returns a
JavaScript object.

Explain about Passport.js.

Passport.js is a widely-used middleware for authentication in Node JS


and Express.js. It offers support for implementing OAuth authentication
using third-party packages, allowing you to integrate social login
functionality into your application easily.

What is Circular dependency in Node JS?

Circular dependency in Node JS occurs when two or more modules


mutually depend on each other, leading to potential issues or errors.
Node JS addresses this by partially loading a module upon detecting a
cycle, breaking the dependency loop

Explain the below line of code. Var http=require(HTTP).

In Node JS, this line of code imports the 'http' module using the 'require'
function and assigns it to the variable 'http', enabling the use of 'http'
module functionalities in the application.

New Section 5 Page 11


module functionalities in the application.

Which method of fs module is used to write a file?

fs.writeFile() method is used to write files. It requires the file path, data
to be written, and a callback function to handle errors or successful
completion.

Which tool automates various tasks of Node JS application?

The tool that automates various tasks of a Node JS application is called


"npm" (Node Package Manager). It helps manage dependencies, run
scripts, and perform tasks like testing, building, and deployment, making
it easier to develop and maintain Node JS applications.

What are the wild cards in Node JS?

In Node JS, wildcards are placeholders used for pattern matching in file
system operations. Two commonly used wildcards are the asterisk (*)
and the question mark (?). The asterisk matches any number of
characters in a file or directory name, while the question mark matches
a single character.

What is the use of MongoDB?

MongoDB is a NoSQL database used in Node JS and Express.js


applications. It is used to store and retrieve data in a flexible, JSON-like
format. Developers can interact with MongoDB using its query language,
perform CRUD operations (Create, Read, Update, Delete), and benefit
from its scalability and high-performance capabilities.

What are streams API?

Node JS Streams API enables efficient handling of streaming data by


processing it in chunks. It includes readable, writable, duplex, and
transform streams. Built-in 'stream' module is used for working with
streams, e.g., reading from a file and writing to another.

Which method of the client object is used in the Node Redis driver to
automatically execute a set of commands?

The "multi" method of the client object is used in the Node Redis driver
to automatically execute a set of commands.

How does concurrency work in NodeJs?

New Section 5 Page 12


Concurrency in Node JS is achieved through an event-driven, non-
blocking I/O model. Asynchronous operations are extensively used,
allowing multiple requests to be processed concurrently.

What is event module?

The event module in Node JS enables event-driven programming


through the use of the EventEmitter class. It provides the ability to
create custom events, define event listeners, and execute code
asynchronously in response to emitted events.

How to execute lint command in Node JS.

To execute the lint command in Node JS, you need to have a linter tool
like ESLint or JSLint installed. Once installed, you can run the linter from
the command line using a specific configuration file (e.g., .eslintrc.js)
and the "lint" command, such as "eslint .".

How to automate tasks in node JS?

Node JS tasks can be automated using task runners like Gulp or Grunt.
These tools enable the definition and configuration of tasks in a
JavaScript file, specifying actions such as file copying, minification, and
testing. Tasks can be executed through command line commands like
"gulp" or "grunt".

New Section 5 Page 13

You might also like