Initialized users route
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
dotenv.config();
|
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
import usersRoute from "./routes/users.js";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
let PORT = process.env.APP_PORT;
|
let PORT = process.env.APP_PORT;
|
||||||
|
|
||||||
@@ -12,10 +16,14 @@ app.use(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("Hello from Express!");
|
res.send("Welcome to ecoconnect.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use("/users", usersRoute);
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Express server running at http://localhost:${PORT}/`);
|
console.log(`ecoconnect server running at http://localhost:${PORT}/`);
|
||||||
});
|
});
|
||||||
|
|||||||
16
server/routes/users.js
Normal file
16
server/routes/users.js
Normal file
@@ -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;
|
||||||
Reference in New Issue
Block a user