-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (40 loc) · 1.15 KB
/
index.js
File metadata and controls
51 lines (40 loc) · 1.15 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
47
48
49
50
51
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const apiRouter = require("./router/apiRouter");
const morgan = require("morgan");
const path = require("path");
const rfs = require("rotating-file-stream");
require("dotenv").config(
{
path: path.join(__dirname, ".env")
}
);
// Initialize MongoDB connection
require("./db/mongoDB");
const app = express();
const port = 3000;
// Enable CORS
const corsoptions = {
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE"
};
app.use(cors(corsoptions));
// create a rotating write stream
const accessLogStream = rfs.createStream("server.log", {
interval: "1d", // rotate daily
path: path.join(__dirname, "logs")
});
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
// setup the logger
app.use(morgan("combined", { stream: accessLogStream }));
app.get("/", (req, res) => {
res.send("Plantify server running successfully!");
});
app.use("/api", apiRouter);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});