-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (43 loc) · 1.19 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const auth = require("./middleware/auth");
const multer = require("multer");
// var storage = multer.diskStorage({
// destination: function(req, file, cb) {
// cb(null, "/my-uploads");
// },
// filename: function(req, file, cb) {
// console.log("asdasdsada", req.file);
// cb(null, file.fieldname + "-" + Date.now());
// }
// });
var upload = multer({ dest: "uploads/" }).single("file");
const app = express();
app.use(bodyParser.json());
app.use(auth);
app.use("/register", require("./routes/register"));
app.use("/login", require("./routes/login"));
app.use("/event", require("./routes/event"));
app.post("/multer", async (req, res) => {
upload(req, res, function(err) {
if (req.file) {
console.log(req.file);
}
console.log(req.file.originalname);
// Everything went fine.
});
});
mongoose
.connect("mongodb://127.0.0.1:27017/mongodbdemo", {
useNewUrlParser: true
})
.then(() => {
console.log("mongodb connected");
})
.catch(err => {
console.log(err);
});
app.listen(3000, () => {
console.log("node server on 3000");
});