-
Notifications
You must be signed in to change notification settings - Fork 1
/
tute9.js
39 lines (29 loc) · 1005 Bytes
/
tute9.js
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
// JavaScript Document
var express= require('express');
var app =express();
var fs=require('fs');
var path =require('path');
var bodyparser=require('body-parser');
app.use(bodyparser());
app.use('/mycssfiles',express.static(__dirname+'/css'));
app.get("/",function(request,response){
response.sendFile('home.html',{root:__dirname});
// response.end("my name is "+JSON.stringify(request.query.name));
});
app.post("/user",function(request,response){
response.end("my name is "+JSON.stringify(request.body.firstname)+" "+JSON.stringify(request.body.lastname));
});
app.get(/^(.+)/,function(request,response){
// response.end(JSON.stringify(request.query));
try{
if(fs.statSync(path.join(__dirname,'views',request.params[0]+'.html'))){
responce.sendFile(request.params[0]+'.html',{root:path.join(__dirname,'views')});
}
}
catch(error){
responce.sendFile('404.html',{root:path.join(__dirname,'views')});
}
});
app.listen(8080,function(){
console.log("server is up");
});