Awd Practicals

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

TITLE: CREATE NODE.

JS APPLICATION TO
DISPLAY SOME MESSAGE BY USING CLIENT
SERVER MODEL.

1.AIM:
TO CREATE NODE.JS APPLICATION TO DISPLAY SOME MESSAGE
BY USING CLIENT SERVER MODEL.

2.Methodology:

Import required modules: The "require" directive is used to load


a Node.js module.
Create server: You have to establish a server which will listen to
client's request similar to Apache HTTP Server.
Read request and return response: Server created in the second
step will read HTTP request made by client which can be a
browser or console and return the response.

3.Process Steps/Description:

How to create node.js web applications


Follow these steps:

Import required module: The first step is to use ?require?


directive to load http module and store returned HTTP instance
into http variable.
For example:

const http = require("http");

Create server: In the second step, we have to use created http


instance and call http.createServer() method to create server
instance and then bind it at port 8081 using listen method
associated with server instance. Pass it a function with request
and response parameters and write the sample implementation
to return "I AM STUDENT OF SRM". For example:

http.createServer( (request, response)=> {


response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('<h1>I AM STUDENT OF SRM</h1>');
}).listen(8081);
console.log('Server running at http://127.0.0.1:8081/');

Combine step1 and step2 together in a file named "main.js".

File: main.js(Coding Given in Sample coding Section)

How to start your server:

Go to start menu and click on the Node.js command prompt.

Now command prompt is open.

Setpath: Find and Remember path where we have saved main.js


file.

Then type cd Setpath(eg: D:\users\) on the command prompt.


After that execute the main.js to start the server as follows:

node main.js
Now server is started.

OPEN THE LOCALHOST PORT 8081 IN BROWSER TO GET THE


REQUIRED MESSAGE DISPLAYED.

4. Sample coding:

const http = require("http");

http.createServer( (request, response)=> {


response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('<h1>I AM STUDENT OF SRM</h1>');
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');

5.Sample Input/Output:
6. Result/inference:

Thus the create a simple NodeJS and running it as client server


model and the simple node is created with server and the
output is verified.
Title : Create a simple Web application using
Express.JS and running it in VS Code editor.

1.AIM:

To create a simple Web application using Express.JS and running


it in VS Code editor.

2.Process Steps/Description:

Step 1: Open windows Powershell , Create an empty folder and


change current working folder to created folder, use the
following commands:

mkdir demo

cd demo

Step 2: Open the created folder in vs code editor by giving


correct locationname, use the following command:
code locationname\demo

Step 3: Now we will create app.js file in our folder using new
file.

Step 4: Initializing file and Installing Express.

Initialize the file and choose yes after giving information to


create package.json file using the following command:

npm init

Install express using following command:

npm i express

Step 5: Write code in app.js file which starts a server and listen
on a local port. It only responds to homepage.

Step 6: Run the application using the following command:


node app.js

Step 7: Now go to http://localhost:5000/ in your browser, We


will see the output.

3.Methodology

It can be used to design single-page, multi-page and hybrid web


applications
It allows to setup middlewares to respond to HTTP Requests.
It defines a routing table which is used to perform different
actions based on HTTP method and URL.

4.Sample coding.

Use the following code in app.js:

const express = require('express');


const app = express();

app.get('/', function (req, res) {


res.send('<h1>Welcome to Homepage</h1>');
})
app.listen(5000,()=>{
console.log("Server running at http://localhost:5000/")
})

5.Sample Input/Output:
6. Result/inference:

Thus the create a simple Express.JS and running it in VS Code


editor and the simple node is created with server and the
output is verified.
Title : Write MONGO SHELL Basic commands
AND EXECUTE WITH PROPER OUTPUT.

1.AIM:

To write Mongo Shell basic commands and execute with proper


output.

2.Process Steps/Description:

OPEN MongoDB Shell , type any database name to start and use
following basic commands in it:

1.Show current database:

db

2.Select or switch database:

use <database name>


eg: use mydb

3.Display help:

help

4.Display help on DB methods:

db.help()

5.Display help on Collection:

db.mycol.help()

6.Show all databases:

show dbs

7.Show all collections in current database:


show collections

8.Show all users on current database:

show users

9.Show all roles on current database:

show roles

3. Input/Output:
4. Result/inference:

Thus the above commands are executed and the output is


verified.
Title : WRITE MONGO CRUD OPERATIONS AND
EXECUTE WITH PROPER OUTPUTS.

1.AIM:

TO WRITE MONGO CRUD OPERATIONS AND EXECUTE WITH


PROPER OUTPUTS.

2,Process Steps/Description:

The following operations are used to create (C), read (R),


update (U), and delete (D) a document in MONGODB. These
operations are often referred to as CRUD operations.

Create operation –

Create operation or Insert operation are used to add new


documents to the collection and if the collection does not exist,
it creates one.
Following command can insert a document on the collection –

db.collection.insert()

Read operation –

This operation reads the documents from the collection. This


process is taken place by executing a query.

The command to read the document is –

db.collection.find()

Update operation –

Update operation is used to modify an existing document.


The command that updates a document is –

db.collection.update()

Delete operation –

Delete operation erases the document from the collection.

Following command performs the operations –

db.collection.remove()

3.Methodology:

The following operations are used to create (C), read (R),


update (U), and delete (D) a document in MONGODB In
Mongodb the CRUD operation refers to the creating, reading,
updating, and deleting of documents.The mongo shell sends the
command to the MongoDB server.
4.Sample Input/Output:

Create:

Create operations add new documents to a collection.

There are two ways to add new documents to collections:

db.collection.insertOne()
db.collection.insertMany()

Here is an example of how a car can be added to the cars


collection:
Read:

Read operations retrieve documents from a collection. If there


is no collection that currently exists, it will automatically create
a new one.

Here is the method to retrieve information:

db.collection.find()

Here is an example of how a car can be found from the cars


collection:
Update:

Update operations modify documents from a collection.

The three ways to add new documents to collections ar:

db.collection.updateOne()
db.collection.updateMany()
db.collection.replaceOne()

Here is an example of how a car can be modified in the cars


collection:
Delete:

Delete operations delete documents from a collection.

There are two ways to add new documents to collections:

db.collection.deleteOne()
db.collection.deleteMany()

Here is an example of how a car can be deleted from the cars


collection:
5. Result/inference:

Thus the above commands are executed and the output is


verified

You might also like