index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import express from "express";
  2. import mongoose from "mongoose";
  3. import cors from "cors";
  4. import dotenv from "dotenv";
  5. import postsRoutes from "./routes/postsRoutes.js";
  6. import userRoutes from "./routes/userRoutes.js";
  7. import getProfilesRoute from "./routes/getProfilesRoute.js";
  8. import profileRoutes from "./routes/profileRoutes.js";
  9. const app = express();
  10. dotenv.config();
  11. app.use(express.json({ limit: "30mb", extended: true }));
  12. app.use(express.urlencoded({ limit: "30mb", extended: true }));
  13. app.use(cors());
  14. app.use("/posts", postsRoutes);
  15. app.use("/auth", userRoutes);
  16. app.use("/users", getProfilesRoute);
  17. app.use("/profile", profileRoutes);
  18. app.get('/', (req,res) => {
  19. res.send('Hello')
  20. })
  21. const host = '0.0.0.0';
  22. // const PORT = process.env.PORT || 5000;
  23. mongoose
  24. .connect(process.env.CONNECTION_URL)
  25. .then(() =>
  26. app.listen(process.env.PORT || 5000,host, () => console.log("Server running on port: " + PORT))
  27. )
  28. .catch((error) => console.log(error));
  29. //useNewUrlParser, useUnifiedTopology, useFindAndModify,
  30. // and useCreateIndex are no longer supported options.
  31. // Mongoose 6 always behaves as if useNewUrlParser,
  32. // useUnifiedTopology, and useCreateIndex are true,
  33. // and useFindAndModify is false.
  34. // Please remove these options from your code.