-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (30 loc) · 955 Bytes
/
app.js
File metadata and controls
40 lines (30 loc) · 955 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
36
37
38
39
40
const express = require("express");
const mongoose = require("mongoose");
const route = require("./routes/model.route")
const path = require("path");
const hbs = require("hbs");
const PORT = 3000;
const app = express();
app.use((req, res, next) => {
const time = Date.now();
next();
console.log(`${req.method} / ${Date.now() - time}ms`);
});
mongoose.connect("mongodb://localhost:27017/users")
.then(() => console.log("Connected to database"));
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "View"));
app.use(express.json());
app.use("/", route);
app.use("/public",express.static("public"));
hbs.registerHelper("times", (n , block) =>{
let result = "";
for (let index = 1; index < n; index++) {
result += block.fn(index);
}
return result;
});
app.use(express.static(path.join(__dirname, "public")));
app.listen(PORT, () => {
console.log(`Server listening on ${PORT} port `);
});