-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
90 lines (74 loc) · 2.37 KB
/
app.js
File metadata and controls
90 lines (74 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var http=require('http')
var calc=require('./calc.js')
var ejs = require('ejs');
var fs=require('fs'); //it will bring the file system module
var bodyParser = require('body-parser')
var mongoose=require('mongoose');
mongoose.connect('mongodb://localhost:27017/basic_node',{useUnifiedTopology: true})
mongoose.connection.once('open',function(){
console.log('connection has been made')
}).on('error',function(error){
console.log('error is',error)
})
const express=require('express');
const app=express();
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.set('view engine','ejs');//express will know from here that we want to use ejs
app.use('/assets',express.static('stuff'));
//app.use(express.static(__dirname + '/assets'));
// app.use('/assets',function(req,res,next){
// console.log(req,url);
// next();
// });
// app.get('/',function(req,res){
// res.send('hello') //response send by server
// })
app.get('/alien',function(req,res){
res.send('hello dfggjhjk')
})
app.get('/contact',function(req,res){
console.log(req.query);
//res.sendFile(__dirname+'/contact.html')
res.render('contact',{qs: req.query});
})
app.post('/contact',urlencodedParser ,function(req,res){
console.log(req.body);
//res.sendFile(__dirname+'/contact.html')
res.render('contact-success',{data: req.body});
})
app.get('/',function(req,res){
//res.sendFile(__dirname+'/contact.html')
res.render('index');
})
//here we got output dynamically
app.get('/profile/:name',function(req,res){
var data={age:67,job:'hjuuuu',hobbies:['eating','jumping']};
res.render('profile',{person:req.params.name,data:data});//to render the view
});
app.get('/alien/:id',function(req,res)
{
const id=req.params.id
res.send('heyyyyy anjali '+id)
})
app.listen(9000,function(req,res){
console.log('runninggggg')
});
// fs.readFile('calc.js','utf8',function(err,data){
// console.log(data)
// })
// fs.writeFile('calc1.js','console.log("done")',function(err){
// console.log("data saved")
// })
// function add(a,b)
// {
// return a+b
// }
// result=add(4,5)
// result2=calc.sub(6,3)
// console.log("the esult="+ result)
// console.log("the esult="+ result2)
// http.createServer(function(req,res){
// res.writeHead(200,{'Content-Trype':'text/html'})
// res.write("welcome back===")
// res.end()
// }).listen(8080)