Professional Documents
Culture Documents
ASSIGNMENT 6 Samarth
ASSIGNMENT 6 Samarth
INTRODUCTION
Connection.js -
//first of all we need to import the predefined Mongodb client const {MongoClient} =
require('mongodb')
//we need to create a url to mongodb database which can be used by program to get
the address of database
const url = "mongodb://localhost:27017";
//here we are creating mongoclient object by passing database url const client = new
MongoClient(url)
//here we declared the function that is used to store our data into database
const Connection = async function(data){
await client.connect()
//cliet.db is used to select the database we want to perform operation with
const db = await client.db('lastAssignment')
//then we selection our collection in which we want to store the data const
collection = await db.collection('Assignment') collection.insertOne(data)
}
exports.insertIntoDatabase=Connection
Mail.js-
exports.transporter=transporter
INDEX.html-
<html>
<head>
<title>Last Assignment</title>
</head>
<body>
<form action="/saveDataIntoDatabase" method="post">
<center>
<label>UserId: </label>
<input type="text" name="name" placeholder=”Enter your Id”>
<br>
<label>Password</label>
<input type="text" name="password" placeholder=”Enter your Id”>
<br>
App.js-
app.get('/',(req,res)=>{
console.log( dirname+"/index.html") res.sendFile( dirname+"/index.html")
})
app.use(bodyparse.urlencoded({extended:false}))
app.post('/saveDataIntoDatabase',(req,res)=>{ console.log(req.body)
const email = req.body.email
const password =
req.body.passwordConnection.insertIntoDatabase({email:email,password:pas
sword})
let info = {
from: 'Akanksha@gmail.com, to: email,
subject: "Your Response has been submitted",
html: "<b>Email</b>"+email+"<b>Password</b>"+password
}
mail.transporter.sendMail(info,(err)=>{ if(err)
console.log(err) else
console.log("success");
})
res.send(“your responce has been submitted”)
res.end;
app.listen(port,()=>{
console.log('server running at port '+port);
});
OUTPUT: -
form: -
Aftersubmission-