axios-demo/app.js

31 lines
865 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var fs=require('fs')
var express=require('express')
var bodyParser=require('body-parser') //用来解释post内容必需要
var multer=require('multer')
var app=express()
var uploadConfig=multer({
dest: './upload'
})
app.use(bodyParser.urlencoded({extended:false})) //extended=false使用内建
app.use(express.static("./public"));
app.get('/api/hello',function(req,res){
res.json({name:'suguo'})
})
app.get('/api/hello1',function(req,res){
console.log(req.query)
console.log(req.query.say)
res.json({name:'suguo'})
})
app.post('/api/post',function(req,res){
console.log(req.body)
res.end()
})
app.post('/api/upload',uploadConfig.any(),function(req,res){
for(var i=0;i<req.files.length;i++){
var file=req.files[i]
fs.renameSync(file.path,'./upload/'+file.originalname)
}
res.end()
})
app.listen(3000);