-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (43 loc) · 1.32 KB
/
server.js
File metadata and controls
53 lines (43 loc) · 1.32 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
/*var express=require('express');
var app=express();
//做一个静态服务中间件 用来返回vue1.js和vue-resource.js
app.use(express.static(__dirname));//已当前目录作为一个静态服务器
app.listen(8080);
app.get('/',function(req,res){
res.sendFile('/get.html',{root:__dirname});
});
app.get('/getUser',function(req,res){
res.send([{name:'zfpx',age:8}])
})*/
/*var express=require('express');
var bodyParser=require('body-parser');
var app=express();
app.use(express.static(__dirname));
app.use(bodyParser.json());//使用这个中间件
app.listen(8080)
app.get('/',function(req,res){
res.sendFile('./get.html',{root:__dirname})
});
app.get('/getUser',function(req,res){
res.send([{name:'zfpx',age:8}])
});
app.post('/postUser',function(req,res){
res.send(req.body);
console.log(req.body)//拿到的是前台传过来的{ name: '珠峰培训', age: 12 }
});*/
var express=require('express');
var bodyParser=require('body-parser');
var app=express();
app.listen(8080);
app.use(express.static(__dirname));
app.use(bodyParser.json());
app.get('/',function(req,res){
res.sendFile('./get.html',{root:__dirname});
});
app.get('/getUser',function(req,res){
res.send([{name:'英语转换',age:8}]);
});
app.post('/postUser',function(req,res){
res.send(req.body);
console.log(req.body)
})