index.ts 702 B

1234567891011121314151617181920212223242526
  1. import express, { type Express, type Request, type Response } from "express";
  2. import dotenv from "dotenv";
  3. import { pinoHttp } from "pino-http";
  4. import { heartbeat } from "./handlers/index.ts";
  5. dotenv.config();
  6. const app: Express = express();
  7. const PORT = process.env.PORT || 3000;
  8. const logging = pinoHttp({});
  9. logging.logger.level = process.env.LOG_LEVEL || "info";
  10. app.use(express.json());
  11. app.use(logging);
  12. app.get("/heartbeat", heartbeat);
  13. app.get("/", (req: Request, res: Response) => {
  14. req.log.debug("Hello");
  15. res.status(200).json({ message: "Hello from TypeScript Express!" });
  16. });
  17. app.listen(PORT, () => {
  18. logging.logger.info(`Server is running at http://localhost:${PORT}`);
  19. });