-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (28 loc) · 1.1 KB
/
app.js
File metadata and controls
33 lines (28 loc) · 1.1 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
// Import the required modules
import express from "express";
import morgan from "morgan";
//importing the requests
import { getDate, createPost } from "./Back_End/scripts/entry.js";
// Initialize the express app
export const app = express();
// export default app;
// Retrieve the port number from environment variables
const PORT = process.env.PORT;
// Middleware
app.use(morgan("dev")); // Morgan is used for logging HTTP requests to the console in a developer-friendly format
app.use(express.json()); // express.json() middleware is used to parse incoming JSON requests
app.use(express.static("Front End"));
app.get("/journal/", async function (req, res) {
const entry = await getDate();
console.log("Did I get the date?");
res.status(200).json({ status: "success", data: entry });
});
app.post("/journal/", async function (req, res) {
const data = req.body;
const entry = await createPost(data);
res.status(201).json({ status: "success", data: entry });
});
// // Start the server and listen on the specified port
// app.listen(PORT, function () {
// console.log(`Server listening on port ${PORT}`);
// });