diff --git a/server/index.js b/server/index.js index f12c27b..efb6255 100644 --- a/server/index.js +++ b/server/index.js @@ -1,8 +1,12 @@ import express from "express"; import dotenv from "dotenv"; -dotenv.config(); import cors from "cors"; +// Routes +import usersRoute from "./routes/users.js"; + +dotenv.config(); + const app = express(); let PORT = process.env.APP_PORT; @@ -12,10 +16,14 @@ app.use( }) ); +app.use(express.json()); + app.get("/", (req, res) => { - res.send("Hello from Express!"); + res.send("Welcome to ecoconnect."); }); +app.use("/users", usersRoute); + app.listen(PORT, () => { - console.log(`Express server running at http://localhost:${PORT}/`); + console.log(`ecoconnect server running at http://localhost:${PORT}/`); }); diff --git a/server/routes/users.js b/server/routes/users.js new file mode 100644 index 0000000..c07ba83 --- /dev/null +++ b/server/routes/users.js @@ -0,0 +1,16 @@ +import { Router } from "express"; +const router = Router(); + +let usersList = []; + +router.post("/", (req, res) => { + let data = req.body; + usersList.push(data); + res.json(data); +}); + +router.get("/", (req, res) => { + res.json(usersList); +}); + +export default router;