-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
43 lines (36 loc) · 1.04 KB
/
main.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
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import mongoose from "mongoose";
import session from "express-session";
import routes from "./routes/routes.js";
import bodyParser from "body-parser";
const app = express();
mongoose.connect(process.env.DB_URI, { useNewUrlParser: true });
const db = mongoose.connection;
db.on("error", (err) => console.log(err));
db.once("open", () => console.log("Connected to database"));
//middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(
session({
secret: "mySecret",
saveUninitialized: true,
resave: false,
})
);
app.use((req, res, next) => {
res.locals.message = req.session.message;
delete req.session.message;
next();
});
app.use(express.static('uploads'));
//set template engine
app.set('view engine', 'ejs');
app.use("", routes);
app.listen(8000, () => {
console.log(`Server is running at http://localhost:8000`);
});