Spaces:
Paused
Paused
| import express from "express"; | |
| import cors from "cors"; | |
| import dotenv from "dotenv"; | |
| import prisma from "./PrismaClient.js"; | |
| // Load environment variables | |
| dotenv.config(); | |
| // App config | |
| const app = express(); | |
| const port = process.env.PORT || 3010; | |
| // Middleware | |
| app.use(express.json()); | |
| app.use(cors()); | |
| app.get("/", (req, res) => { | |
| res.send("Hello World!"); | |
| }); | |
| // Routes | |
| app.get("/api/users", async (req, res) => { | |
| try { | |
| const users = await prisma.user.findMany(); | |
| res.json(users); | |
| } catch (error) { | |
| console.error("Error fetching users:", error); | |
| res.status(500).json({ error: "An error occurred while fetching users." }); | |
| } | |
| }); | |
| // Start server | |
| app.listen(port, () => { | |
| console.log(`Server started on port ${port}`); | |
| }); | |
| export default app; |