Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (46 loc) · 1.59 KB
/
Copy pathserver.js
File metadata and controls
61 lines (46 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
// 4/4/2024 - add support for db sqlite
import sqlite3 from "sqlite3";
import express from "express";
import usersRouter from "./routes/users.js";
import cardsRouter from "./routes/cardsRouter.js";
import CardController from "./controllers/cardsController.js";
import path from "path";
// If your script is in the same directory as the cards.db
const dbPath = path.resolve(process.cwd(), "cards.db");
const cardsController = new CardController(dbPath);
cardsController.queryAll();
const app = express();
// using the public path
app.use(express.static("public"));
// to get data from request
app.use(express.urlencoded({ extended: true }));
// this is from the body
app.use(express.json());
app.set("view engine", "ejs");
//app.use(logger); // have to put the middleware before the route
// running the logger only on specific request
// we can run few middlewares as params before handling the request
// we can even put the logger multiple times
app.get("/", logger, (req, res) => {
console.log("Request received");
//// status and message:
//res.status(200).send("Hi there! 3");
//// download file
// res.download("server.js");
//// render template or page
res.render("CardExamplePage", {
fullname: "Shefy Gur-Ary",
title: "Software Developer / Tech Lead",
email: "shefyg@gmail.com",
linkedin: "https://www.linkedin.com/in/shefy-gur-ary/",
phone: "0541234567",
github: "https://github.com/shefyg",
});
});
function logger(req, res, next) {
console.log(`Logging... request ${req.originalUrl}`);
next();
}
// users router
app.use("/users", usersRouter);
app.listen(3000);