React JS and MongoDB QB
React JS and MongoDB QB
QUESTION BANK
1) What is web development framework?
Ans
• A web development framework is a collection of tools, libraries
and technologies that a used to create web applications and websites.
• It provides a basic structure and set of conventions for developers to build
web applications quickly and efficiently
2) Why do we use web framework? Give any two reasons.
Ans:
1. Saves time: The most striking feature of web framework is that it saves time and
energy in developing any app because the developer doesn't need to worry about
session handling. error handling and authentication logic. These functions are
taken care of by web frameworks.
2. Flexibility and customizable : Add-ons, themes, plugins, widgets enable rapid
customization on the web application. This brings out a lot of flexibility in code
development
3) What are the components of web development framework?
Ans.:
The components of web development framework are-
(1) User
(2) Browser
(3) Web Server
(4) Backend services
4) Give the importance of browser
ans.:
The browser plays three roles in web framework
It provides communication to and from the web server.
It interprets the data from the server and displays the visual output.
The browser handles user interaction through the keyboard, mouse, touchscreen or
other input device and takes the appropriate action.
5) What is GET and POST request ?
Ans :
i) GET: The GET request is typically used to retrieve data from the server. This
data can be inthe html files or images.
ii) POST: The POST request is used for sending the data to the server. For example -
Creditcard details while performing online shopping
9) What is
MVC? Ans.:
1. Model: This part of the architecture is responsible for managing the
application data. The module responds to the request made from view. The model
gives instructions to controller to update when the response is made.
2. View: This part takes care of the presentation of data. The data is presented in des
format with the help of view. This is a script based system using JSP, ASP, PHP
and so on.
3. Controller: The controller receives input, validates it and then performs business
operation that modify the state of the data model. The controller basically responds
to user required and performs interaction with the model.
Disadvantages of MVC
4. Explain the different stacks in webDevelopment?
● Nodejs
● Reasons of Nodejs
● MongoDB
● Express
● Features of Express
● Angular
5. Explain the role of
(i)Express (ii) Angular (iii) Node (iv) Mongo DB (v) React
Express
o Definition
o Need Of Express JS
o Features of ExpressJS
o Advantages and disadvantages of Express JS
o Simple Program in ExpressJS
Angular
o Definition
o Need Of Angular
o Features of Angular
o Advantages and disadvantages of Angular
o Simple Program in ExpressJs
MongoDB
o Define
o Difference between NOSQL And MongoDB
o Features of
o Architectures of MongoDB
React
o Definition
o Need of React
o Component Based
o No Templates
o Isomorphic
UNIT =II NODE JS
PART A QUESTIONS
1.What is Node.js ? Give its uses.
Ans.: Node JS is an open source technology for server. Using Node.js we can run
JavaScript on server.
1) It can create, open, read, delete, write and close files on the server.
2 What is NPM?
Ans: The NPM stands for Node Package Manager. NPM consists of two main
parts:
Ans: The cluster module helps in creating a child process. Both the main and child
can run simultaneously and share the same server port
For example
emp_dept {
5. What is EventEmitter ?
Basically EventEmitter is a class which can be used to raise and handle custom
even.
Syntax
Timeout(function.delay in milliseconds)
Example code
Console.log(Task1')
Timeout(function() (console.log("Taks2: Executing After 4 seconds")),4000);
console.log("Task3)
pipeExample.js
Var fs =require("fs")
Var rs=fs.createRoadStream(input.txt');
rs.setEncoding(8)
var ws=fs.createWriteStream('output.txt');
rs.setEncoding("utf8");
rs.pipe(ws)
Ans: The query string specifies the parameters of the data that is being queried
from a website's database. Each query string is made up of a parameter and a value
joined by the equals (-) sign. In case of multiple parameters, query strings are
joined using the ampersand (&) sign. The parameter can be a number, string,
encrypted value or any other form of data on the database.
Ans. The ClientRequest object is used to monitor and handle the response from the
server. For implementing the ClientRequest object the call to the http.request() is
made.
http.request(options.callback)
The event loop allows Node.js to perform non-blocking I/O operations despite
the fact that JavaScript is single-threaded.
It is done by assigning operations to the operating system whenever and wherever
possible.
14. What is node package Module?
Part B Questions
1. List the builtin Modules of Nodejs?
2. How NodeJs can be Installed ?
● Looking at the Node.js Install Location
Data Model) for MongoDB, Express extends Node’s HTTP capabilities, and so on.
Node Packaged Modules include a package.json file that defines the packages.
The package.json file includes informational metadata, such as the name,
version author, and contributors, as well as control metadata, such as dependencies
and other requirements that the Node Package Manager uses when performing
❖ It allows you to find, install, remove, publish, and do everything else related
to Node Package Modules.
❖ The Node Package Manager provides the link between the Node Package
Registry and your development environment.
❖ Define EventModel
CallBack Model
6. Why timers are used in Nodejs?
❖ Need of timer
osetImmediate().
osetInterval()
osetTimeout():
onextTick
Definition
o Definition of Closure
❖ Callback Chaining
● Creating Buffers
● Writing to Buffers
● Copying Buffers
● Slicing Buffers
● Concatenating Buffers
9. How File Handling is done in Nodejs?
● Define Data Stream
● Readable Streams
● Writable Streams
● Duplex Streams
● Transform Streams
● Compressing/Decompressing Streams
❖ There are various types of NOSQL databases such document, key-value, wide
column and graph.
❖ Using NOSQL we can maintain flexible schemas and these schemas can be
scaled easily with large amount of data
3. Why NoSQL?
The concept of NoSQL (Not Only SQL) consists of technologies that provide storage
and retrieval without the tightly constrained models of traditional SQL relational
databases.
The motivation behind NoSQL is mainly simplified designs, horizontal scaling, and
finer control of the availability of data
4. List the features of MongoDB
Ans
1) It is a schema-less, document based database system.
2) It provides high performance data persistence.
3) It supports multiple storage engines.
4) It has a rich query language support.
5) MongoDB provides high availability and redundancy with the help of
replication.That means it creates multiple copies of the data and sends these
copies
to a different server o that if one server fails, then the data is retrieved from another
server.
4. How the terms in MongoDB are different from SQL?
Or
Difference between SQl and NoSQL
Ans:
5. What is JSON?
JSON, or JavaScript Object Notation, is a simple, readable data structure
format. As an alternative to XML, it is primarily used to transmit data between a
server and a web application
JSON is made up of two main components: keys and values. They form a
key/value pair when combined.
Key: A key is a string which is enclosed in quotation marks.
Value: A value can be a string, a number, a boolean expression, an array, or an
object.
Key/Value Pair: A key value pair has a specific syntax, with the key coming first,
followed by a colon, and then the value. Key/value pairs are separated by commas.
6. Define Collections and documents
A collection is simply a grouping of documents that have the same or a similar purpose.
Capped collections work great for objects that have a high rate of insertion, retrieval,
and deletion.
Creating Capped Collection
To create a capped collection, we use the normal createCollection command but with
capped option as true and specifying the maximum size of collection in bytes.
In addition to collection size, we can also limit the number of documents in the collection
using the max parameter −
Stopping MongoDB
use admin
db.shutdownServer()
13. What is Mongo Shell and list the commads used in Mongo Shell?
The MongoDB shell is an interactive shell provided with MongoDB that allows you to
access, configure, and administer MongoDB databases, users, and much more.
16. How will you count the number of users in admin Database?
use admin
cur = db.system.users.find()
cur.count()
db.dropUser(username)
Where,
name is the name of collection options is an optional field. This field is used to
specify some parameters such as maximum number of documents and so on.
db.posts.insertMany([
{
❖ Write concern describes the guarantee that the MongoDB connection provides
when reporting on the success of a write operation.
The strength of the write concern determines the level of guarantee
24. Explain the MongoDBClient in detail.
Ans: The MongoDBClient object provides interactions to connect to the database.
Following are some commonly used method of MongoDBClient object
Method Purpose
db.collection.mapReduce(
function() {emit(key,value);}, //map function
function(key,values) {return reduceFunction}, { //reduce
function
out: collection,
query:
document, sort:
document, limit:
number
}
)
Where
1) map function: It uses emit() function in which it takes two parameters key
and value key. Here the key is on which we make groups(such as group by name,
or age) and the second parameter is on which aggregation is performed like
avg(), sum() is calculated on.
3) out: It will specify the collection name where the result will be stored.
Part-B
1. What is NoSQL? What is the need for it? Enlist the various features of
NoSQL?
Definition
❖ Why NoSQL
❖ Features of NoSQL
❖ Definition
❖ Advantages
❖ Why Mongodb
❖ Understanding collections
❖ Understanding documents
❖ MongoDB datatypes
❖ DeNormalizing
❖ Capped Collections
❖ Enterprise version
❖ Starting MongoDB
o Mongod
❖ Stopping MongoDB
4. Explain how to create users in MongoDB? Also enlist and explain the
various roles of the users.
Creating User Account
Listing the user names
Counting the no of user
Assigning roles to each user
Removing Users
❖ Creation of documents
❖ Updation of doucuments
❖ Deletion of documents
8)Explain insertion and deletion database operation using Node JS ?
Adding the MongoDB Driver to Node.js
Connecting to MongoDB from Node.js
Understanding the Write Concern
Connecting to MongoDB from Node.js Using the MongoClient Object
9.What is the purpose of MapReduce explain with a suitable example?
Definition
❖ Purpose of MapReduce
❖ Components Of MapReduce
❖ Example
❖ Program
REACT
QUESTION BANK
PART-A
1) What is MEAN & MERN stack?
The MEAN (MongoDB, Express, AngularJS, Node.js) stack was one of the early
open-source stacks that epitomized this shift toward SPAs and adoption of NoSQL.
AngularJS, a front-end framework based on the Model View Controller (MVC)
design pattern, anchored this stack. MongoDB, a very popular NoSQL database, was
used for persistent data storage.
Node.js, a server-side JavaScript runtime environment, and Express, a web-
server built on Node.js, formed the middle-tier, or the web server.
Bootstrap is a free, open source front-end development framework for the creation of
websites and web apps. Designed to enable responsive development of mobile- first
websites, Bootstrap provides a collection of syntax for template designs.
The most popular CSS framework, has been adapted to React and the project is
called ReactBootstrap.
This library not only gives us most of the Bootstrap functionality, but the
components and
widgets provided by this library also give us a wealth of information on how to design
our own widgets and components
4. What is React and which layer of web application is it responsible for?
❖ Class components are also known as stateful components because they have
their own internal state and can use lifecycle methods for managing the
component's behavior over time.
❖ Class components are also known as stateful components because they have
their own internal state and can use lifecycle methods for managing the
component's behavior over time.
❖ Imperative.
❖ Declarative
Component-Based
No Templates
Isomorphic Node.js
Modules Node.js and
npm
Node.js Is Event Driven
Express
MongoDB NoSQL
Document-Oriented
JavaScript Based
React-Router
React-Bootstrap
Webpack
2. Explain the steps of installation of ReactJS. Write a program using
ReactJS.
To install ReactJS and create a basic React application, you'll need to follow these
steps:
Step 1: Install Node.js and npm
ReactJS relies on Node.js and npm (Node Package Manager) for development and
package management. If you don't have Node.js and npm installed, you can
download and install them from the official website: https://nodejs.org/
Step 2: Create a React Application
Once you have Node.js and npm installed, you can create a new React application
using `create-react-app`, which is a tool that sets up a basic React project structure
with all the necessary dependencies and configurations.
Open your terminal or command prompt and run the following command: npx
create-react-app my-react-app
Replace `my-react-app` with the name you want to give to your React application.
This command will create a new directory with the specified name and set up a
basic React project inside it.
Step 3: Navigate to Your Project Directory
After the command has completed, navigate to your project directory: cd
my-react-app
Step 4: Start the Development Server
To start the development server and run your React application, use the following
command:
npm start
This will start the development server, and your React app will be available at
`http://localhost:3000` in your web browser.
Step 5: Create a React Component
Now, let's create a simple React component. React components are typically
defined in `.js` or `.jsx` files.
In your project directory, open the `src` folder and create a new file called
`HelloWorld.js`. Inside this file, you can define a basic React component:
```javascript
import React from 'react';
function HelloWorld()
{ return (
<div>
<h1>Hello, React!</h1>
<p>This is a basic React component.</p>
</div>
);
}
function Counter() {
const [count, setCount] = useState(0);
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
```
In this example, a `POST` request to `/api/users` will create a new user resource on
the server.
3. `PUT` Method**
The `PUT` method is used to update an existing resource or create it if it doesn't
exist. It replaces the entire resource with the new data.
5. Explain Modularization and Webpacks in detail with the necessary
commands and steps
Modularization and Webpack are essential concepts in modern JavaScript
development, especially in the context of building complex web applications.
Modularization:
Modularization is the practice of breaking down a large codebase into smaller,
self-contained modules. Each module focuses on a specific functionality or
feature of the application. Modularization helps in organizing code, improving
maintainability, and facilitating collaboration among developers.
Step 1: Create Module
Files** Step 2: Use Modules
Webpack:
Webpack is a popular JavaScript module bundler. It allows you to bundle all your
modules and their dependencies into a single file (or multiple files) for use in the
browser. This helps optimize the loading and execution of JavaScript in web
applications.
Here are the steps to use Webpack:
Step 1: Install Webpack**
You need to install Webpack and its command-line interface (CLI) globally if you
haven't already:
Step 2: Create a Webpack Configuration**
Create a `webpack.config.js` file in your project root to configure Webpack. Here's
a basic configuration:
```javascript
// webpack.config.js
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
path: path.resolve( dirname, 'dist'),
},
};
In this configuration:
- `entry` specifies the entry point of your application (e.g., `app.js`).
- `output` specifies the output file and path (e.g., `bundle.js` in the `dist` folder).
Step 3: Bundle Modules
Run Webpack to bundle your modules
Step 4: Include Bundled File in HTML**
In your HTML file (e.g., `index.html`), include the bundled JavaScript file:
```html
<!DOCTYPE html>
<html>
<head>
<title>Webpack Example</title>
</head>
<body>
<script src="dist/bundle.js"></script>
</body>
</html>
Step 5: Run the Application
PART-C
6. Develop an Employee Management System Application using NodeJS
API.
Creating a full-fledged Employee Management System (EMS) application
using a Node.js API is a complex task that involves several components,
including a database for storing employee data, authentication, and
frontend development. Below is a simplified example of a Node.js API for an
EMS that allows you to perform basic CRUD (Create, Read, Update,
Delete) operations on employee records.
Step 1: Set Up Your Project**
Create a new directory for your project and initialize a Node.js project:
mkdir employee-management-system
cd employee-management-system
npm init -y
Step 2: Install Dependencies**
You'll need the following dependencies for your project:
- `express`: To create the API and handle HTTP requests.
- `mongoose`: To interact with a MongoDB database.
- `dotenv`: To manage environment variables.
- `body-parser`: To parse JSON request bodies.
Install these dependencies using npm:
npm install express mongoose dotenv body-parser
app.use('/api/employees', require('./routes/employees'));
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Step 5: Create Employee Model**
Create a `models/Employee.js` file to define the Employee model using
Mongoose:
```javascript
const mongoose = require('mongoose');
const employeeSchema = new
mongoose.Schema({ firstName: String,
lastName: String,
email: String, position:
String, department:
String, hireDate: Date,
});