Slip Solution1 All Done
Slip Solution1 All Done
(done)
console.log(res)
Or
var uc
res.write(uc = str.toUpperCase());
res.end();
}).listen(8080);
b) Create a Node.js file that demonstrate create database student DB and student table (Rno, Sname,
Percentage) in MySQL.
(done)
create_db.js
host: "localhost",
user: "root",
password: "root"
});
con.connect(function(err) {
console.log("Connected!");
console.log("Database created");
});
});
create_table.js
host: "localhost",
user: "root",
password: "root",
database: "studentdb"
});
con.connect(function(err) {
console.log("Connected!");
double)";
console.log("Table created");
});
});
Slip 2a) Create a Node.js Application that uses user defined Module to return the factorial of
given number.(done)
//FACT.JS
var fact={
factorial: function(n)
{
var f=1,i;
for(i=1;i<=n;i++)
{ f=f*i;
module.exports=fact
//MainFact.js
var mymod=require('C:/Users/Public/node_prog/fact.js');
mymod.factorial(5);
b) Create a Node.js Application that contain the Employee Registration details and
write a JavaScript to validate DOB, Joining Date, and Salary.
empMain.js
var app = require('express')();
var http = require('http').Server(app);
var bodyParser = require('body-parser');
app.use(bodyParser.json());
http.listen(8080, function(){
console.log('listening on *:8080');
});
registration.html
<html>
<head>
</head>
<body>
<h1>Registration Form</h1>
<form action="/"method="POST">
</form>
</body>
</html>
Slip No.3 a and Slip no. 30.Create a Node.js Application that uses
user defined module circle.js which exports functions area() and
circumference() and display details on console.(done)
circle.js
var circle={
area: function(r)
{ var pi=3.14,a;
a=pi*r*r;
},
circumference: function(r)
{
var pi=3.14,c;
c=2*pi*r;
};
module.exports=circle
mycircle.js
var mymod=require('C:/Users/Public/node_prog/circle.js');
mymod.area(5);
mymod.circumference(5);
// studentRegistration.js
app.use(bodyParser.json());
res.sendFile(__dirname + '/studentRegistration.html');
});
res.write('<h3>Last Name</h3>'+lastName);
res.write('<h3>Date of Birth</h3>'+dateOfBirth);
res.write('<h3>Address</h3>'+address);
res.write('<h3>Contact</h3>'+tel);
res.write('<h3>Email</h3> '+email);
// res.write('<'+password);
});
studentRegistration.html
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
<span class="message"></span>
</div>
<div class="field-row">
</select>
</div>
<div class="field-row">
<label class="form-label"></label>
</div>
</form>
Slip 4:aFirst name Last name and calculate the age(done)
// firstlastnamedemo.js
exports.name= function(fn,ln,age)
//mainDemo.js
nm.name(fn,ln,age);
4b:Teacher’s Profile System
var prompt=require('prompt-sync')();
var name,subject,experience
//function createTeacherProfile() {
console.log(`\nTeacher Profile:`);
console.log(`Name: ${name}`);
console.log(`Subject: ${subject}`);
//}
// createTeacherProfile();
const host='127.0.0.1'
const port='8080';
const server=http.createServer((req,res)=>{
res.setHeader('content-plain','text-plain')
res.write(`<html lang="en">
<head>
<meta charset="UTF-8">
<title>Teacher's Profile</title>
</head>
`Teacher's experience`+experience+`</td></body></html>`)
res.end();
});
server.listen(port,host,()=>{
console.log('server running');
})
Slip No.5.
buffer.js
if(result < 0) {
} else {
buffer1.copy(buffer2);
b) Create a Node.js file that Insert Multiple Records in "student" table, and
display the result object on console.(done)
insert_record.js
host: "localhost",
user: "root",
password: "1234567",
database: "studentdb"
});
con.connect(function(err) {
console.log("Connected!");
var sql = "INSERT INTO student (rollno,name, percentage) VALUES ?";
var values = [
[1,'abc', 77.6],
[2,'def', 89.6],
[3,'ghi', 91.6]
];
console.log(result);
});
});
Slip No.6. a.Create a Node.js Application that opens the requested file
and returns the content to the client if anything goes wrong throw
404 error.(done)
Demo_server.js
var fs = require('fs');
http.createServer(function (req, res) {
if (err) {
res.write(data);
return res.end();
});
}).listen(8080);
//summer.html
<!DOCTYPE html>
<html>
<body>
<h1>Summer</h1>
</html>
//Winter.html
<!DOCTYPE html>
<html>
<body>
<h1>Winter</h1>
</body>
</html>
b) Create a Node js file that Select all records from the "customers" table,
and display the result object on console.(done)
//all_cust.js
host: "localhost",
user: "root",
password: "root",
database: "mydb"
});
con.connect(function(err) {
console.log(result);
});
});
Slip 7
a. Create nodejs to read two file names from user and append contents of
first file into second file .
data1=Buffer.alloc(1040);
fs.readFile(file1,{encoding:'utf8'},function(err,data){ if (err){
console.log(err);
console.log('data1=',data1=data);
});
fs.readFile('file2.txt',{encoding:'utf8'},function(err,data){ if (err){
console.log(err);
console.log(data);
});
fs.appendFile(file2,data1,(err)=>{
if (err){
console.log(err);
else
fs.readFile('file2',{encoding:'utf8'},function(err,data)
{ if (err){
console.log(err);
console.log(data);
});
Slip 8AA using node.js create a webpage to read 2 file names from user and
combine third file with all the content into uppercase.
data1=Buffer.alloc(1040);
data2=Buffer.alloc(1040);
fs.readFile(file1,{encoding:'utf8'},function(err,data){ if (err){
console.log(err);
console.log('data1=',data1=data);
});
fs.readFile('file2',{encoding:'utf8'},function(err,data){ if (err){
console.log(err);
console.log(data);
});
fs.appendFile(file2,data1,(err)=>{
if (err){
console.log(err);
else
fs.readFile('file2.txt',{encoding:'utf8'},function(err,data)
{ if (err){
console.log(err);
console.log('Data2=',data2=data);
});
})
var http = require('http')
var host='127.0.0.1'
const port=8080;
const server=http.createServer((req,res)=>{
res.setHeader('content-plain','text-plain')
var uc=data2.toUpperCase();
res.write(uc=data2.toUpperCase());
res.end();
});
server.listen(port,host,()=>{
})
Slip 8b
create node.js application that contain student registration details & validate
student firstname & lastname should not contains any special symbols/digits &
age should be between 6 to 25
// server.js
res.sendFile(__dirname + '/index.html');
});
app.post('/register', [
if (!errors.isEmpty()) {
res.send('Registration successful!');
});
app.listen(PORT, () => {
});
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Registration</title>
</head>
<body>
<br>
<br>
<label for="age">Age:</label>
<br>
</form>
</body>
</html>
//Slip No.9. A.Create a Node.js file that writes HTML form with an
upload field.(done)
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}).listen(8080);
var prompt=require('prompt-sync')();
var http = require('http');
var name,subject,experience
console.log(`\nTeacher Profile:`);
console.log(`Name: ${name}`);
console.log(`Subject: ${subject}`);
const host='127.0.0.1'
const port='8080';
const server=http.createServer((req,res)=>{
res.setHeader('content-plain','text-plain')
res.write(`<html lang="en">
<head>
<meta charset="UTF-8">
<title>Teacher's Profile</title>
</head>
`Teacher's experience`+experience+`</td></body></html>`)
res.end();
});
server.listen(port,host,()=>{
console.log('server running');
})
download_jpg.js
var fs = require('fs'),
request = require('request');
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
download('https://www.google.com/images/srpr/logo3w.png', 'google.png',
function(){
console.log('done');
});
11 aCreate a Simple Web Server using Node.js that shows the college information.
const host='127.0.0.1'
const port='8080';
const server=http.createServer((req,res)=>{
res.setHeader('content-plain','text-plain')
res.write(`<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
.topnav {
overflow: hidden;
background-color: #333;
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
text-decoration: none;
font-size: 17px;
.topnav a:hover {
background-color: #ddd;
color: black;
.topnav a.active {
background-color: #04AA6D;
color: white;
</style>
</head>
<body>
<div class="topnav">
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<div style="padding-left:16px">
</div>
</body></html>`)
res.end();
});
server.listen(port,host,()=>{
console.log('server running');
})
11b) Using Node.js create a Computer Science department
portal.
const http = require('http')
const host='127.0.0.1'
const port='8080';
const server=http.createServer((req,res)=>{
res.setHeader('content-plain','text-plain')
res.write(`<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
.topnav {
overflow: hidden;
background-color: #333;
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
text-decoration: none;
font-size: 17px;
.topnav a:hover {
background-color: #ddd;
color: black;
.topnav a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<div class="topnav">
<a href="#bca">BCA</a>
<a href="#bcs">BCS</a>
<a href="#cds">CDS</a>
</div>
<div style="padding-left:16px">
</div>
</body></html>`)
res.end();
});
server.listen(port,host,()=>{
console.log('server running');
})
}
var listener2 = function listener2(){
console.log('We have executed listener2');
}
ee.addListener('connection',listener1);
ee.on('connection',listener2);
var eventListeners=
require(events).EventEmitter.listenerCount(ee,'connection');
console.log(eventListeners +"Listener(s) listening to
coonection event");
ee.emit('connection');
ee.removeListener('connection',listener1);
console.log('Now Listener1 will not listen ');
ee.emit('connection');
eventListeners=require(events).EventEmitter.listenerCount(
ee,'connection');
console.log(eventListeners +"Listener(s) listening to
cnonection event");
12b) Using Node.js create a User Login
System.
Slip No.13 and Slip no.29. Create a Node.js application that uses user
defined module to find area of rectangle and display details on
console. (done)
rect.js
var rect={
area: function(l,b)
var a;
a=l*b;
console.log('area of rectangle is:'+a);
}};
module.exports=rect
myrect.js
var mymod=require('C:/Users/Public/node_prog/rect.js');
mymod.area(5,4);
search_word.js
var fs=require('fs');
if(data.includes('dfgdf')){
console.log(data.toString())
else
});
Slip No.22. Create a Node.js application to count no of lines in a file in
fille and display count on console
linecount.js
const fs = require('fs');
var linesCount = 0;
var rl = readline.createInterface({
input: fs.createReadStream(file),
output: process.stdout,
terminal: false
});
});
rl.on('close', function () {
});
fs = require('fs');
if (err) {
throw err;
http.createServer(function(request, response) {
response.write(html);
response.end();
}).listen(8000);
});
response.sendFile('absolutePathToYour/htmlPage.html');
});