Lab manual-ADWANCED WEB LAB MANUAL
Lab manual-ADWANCED WEB LAB MANUAL
1. Methodology
Import required modules: The "require" directive is used to load a
Node.js module.
2. Process Steps/Description
node console_example1.js
2. Create server: In the second step, you 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
"Hello World". For example:
node main.js
4. Sample coding
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
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 in VS Code editor and
the simple node is created with server and the output is verified.
2.Title : To create a simple Web application using Express.JS and running it in
VS Code editor.
1. Process Steps/Description
Step 1: Create an empty folder and move it into that folder from your VS Code
editor, use the following command.
mkdir demo
cd demo
Step 1: Create an empty folder and move it into that folder from your VS Code
editor, use the following command.
mkdir demo
cd demo
code .
Step 3: Now create a file app.js file in your folder as shown below.
Step 4: Installing Module and Express
Install the modules using the following command.
3.Methodology
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.
3.
Title : To create a basic routing Web application using Express.JS and running
it in VS Code editor.
2. Process Steps/Description
Route definition takes the following structure:
app.METHOD(PATH, HANDLER)
Where:
3.Methodology
Respond to POST request on the root route (/), the application’s home page:
app.post('/', function (req, res) {
res.send('Got a POST request')
})
5.Sample Input/Output:
6. Result/inference:
Express.js can be used with any template engine.Use different Jade templates
to create HTML pages dynamically.
In order to use Jade with Express.js, create sample.jade file inside views folder
and write following Jade template in it.
2,Process Steps/Description(File:Sample.jade)
doctype html
html
head
title Jade Page
body
h1 This page is produced by Jade engine
p some paragraph here..
Now, write the following code to render above Jade template using
Express.js.
4.Methodology
Fromthe above example, first we import express module and then set the view
engine using app.set() method.
The set() method sets the "view engine", which is one of the application
setting property in Express.js.
In the HTTP Get request for home page, it renders sample.jade from the views
folder using res.render() method.
5.Sample coding File: server.js
res.render('sample');
});
5.Sample Input/Output:
6. Result/inference:
Thus the create Jade Engine with Express.js and the output is verified.
5.
1.Title : To create Basic commands for Mongo Shell to get started with using
MongoDB.
2,Process Steps/Description
Basic Commands
Display help on DB
db.help() db.help()
methods
>show dbs
>help
4. Result/inference:
Thus the above commands are executed and the output is verified
6.
2,Process Steps/Description
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.
Read operation – This operation reads the documents from the collection. This
process is taken place by executing a query.
Delete operation – Delete operation erases the document from the collection.
3.Methodology
The following operations are used to create (C), read (R), update (U),
and delete (D) a document in MONGODB
db.collection.insertOne()
db.collection.insertMany()
db.cars.insertOne(
//insert Civic 2017 into cars
{
name: "Civic"
model: "2017"
}
)
Read
Read operations retrieve documents from a collection. If there is
no collection that currently exists, it will automatically create a
new one.
db.collection.find()
db.cars.find(
//find the 2017 models
{ model: "2017"}
)
Update
Update operations modify documents from a collection.
db.collection.updateOne()
db.collection.updateMany()
db.collection.replaceOne()
db.cars.updateMany(
//search the query
{ name: "Civic" }
//update the query
{ $set: {model: "2020"} }
)
Delete
Delete operations delete documents from a collection.
db.collection.deleteOne()
db.collection.deleteMany()
db.cars.updateMany(
//delete all cars from 2017
{ name: "Civic" }
)
5. Result/inference:
Thus the above commands are executed and the output is verified