-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (29 loc) · 848 Bytes
/
app.js
File metadata and controls
35 lines (29 loc) · 848 Bytes
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
const express = require("express");
const fileUpload = require("express-fileupload");
const uploadRouter = require("./routes/upload");
// the app
const app = express();
// middlewares
// 1. for uploading files to our server
app.use(
fileUpload({
// The option will let express-fileupload create the
// (parent) directory path for mv() method when it doesn’t exist
createParentPath: true,
/**
* set the file size limit to 1 MB and abort the request process by
* returning an HTTP 413 response when the file exceeds the limit.
*/
limits: {
fileSize: 1024 * 1024, // 1 MB in bytes
},
abortOnLimit: true,
})
);
// the routes
app.use("/upload", uploadRouter);
app.use("/download", require("./routes/download"));
// listen
app.listen(3000, () => {
console.log("listening on port 3000");
});