-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.js
29 lines (25 loc) · 773 Bytes
/
app1.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
var express = require('express')
var app = express();
console.log(express);
// to listen to the port we can directly use this line
var http = require('http').Server(app).listen(8080);
var upload = require('express-fileupload');
app.use(upload()); // upload function inside express
console.log('Server Started');
app.get("/", function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.post("/", function(req, res) {
if (req.files) {
var file = req.files.filename;
var filename = file.name;
file.mv("./upload/" + filename, function(err) {
if (err) {
console.log(err);
return res.end("Error Occurred")
} else
res.end("File Uploaded Successfully")
console.log("file upload sucessfully");
})
}
})