blob: f7d839525204a391fceab6ae5485037ed67689b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import express from "express";
import { config } from "dotenv";
import morgan from "morgan";
import createHttpError from "http-errors";
config();
const app = express();
const PORT = Number(process.env.PORT) || 4000;
app.use(morgan("dev"));
app.get("/", (req, res) => {
res.json("hi there");
});
app.use((req, res, next) => next(createHttpError.NotFound()));
const errorHandler = (error, req, res, next) => {
const status = error?.status || 500;
res.status(status).json({
status,
message: error?.message || "Something Went Wrong",
});
};
app.use(errorHandler);
app.listen(PORT, () => {
console.log(`⚔ api @ http://localhost:${PORT}`);
});
|