-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
33 lines (32 loc) · 775 Bytes
/
index.mjs
File metadata and controls
33 lines (32 loc) · 775 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
import express from "express";
import "dotenv/config";
import chalk from "chalk";
import cors from "cors";
import todoroute from "./Routes/todos.mjs";
import postroute from "./Routes/post.mjs";
const app = express();
const PORT = process.env.PORT || 2494;
app.use(express.json());
app.use(cors());
app.listen(PORT, () => {
console.log(chalk.green(`Server is running on port ${PORT}`));
});
app.get("/", (req, res) => {
try {
res.status(200).send({
message: "Helow Express Js",
});
} catch (error) {
console, log(error);
res.status(500).send({
message: "Internal Server Error",
});
}
});
app.use("/todos", todoroute);
app.use("/posts", postroute);
app.use("*", () => {
res.status(404).send({
message: "Page Not Found",
});
});