index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import dotenv from 'dotenv';
  2. dotenv.config();
  3. import express from 'express';
  4. import bodyParser from 'body-parser';
  5. import mongoose from 'mongoose';
  6. import cors from 'cors';
  7. import planRoutes from './routes/plans.routes.js';
  8. import imageRoutes from './routes/images.routes.js';
  9. import mealRoutes from './routes/meals.routes.js';
  10. import settingsRoutes from './routes/settings.routes.js';
  11. import usersRoutes from './routes/users.routes.js';
  12. const app = express();
  13. app.use(cors());
  14. app.use(bodyParser.json());
  15. app.use('/uploads', express.static('uploads'));
  16. app.use('/plans', planRoutes);
  17. app.use('/images', imageRoutes);
  18. app.use('/meals', mealRoutes);
  19. app.use('/settings', settingsRoutes);
  20. app.use('/users', usersRoutes);
  21. const ATLAS_URI = 'mongodb+srv://ramonap:emealadmin@emealaycluster.8oblc.mongodb.net/emealay?retryWrites=true&w=majority';
  22. const PORT = process.env.PORT || 5000;
  23. mongoose.connect(ATLAS_URI, { useNewUrlParser: true, useUnifiedTopology: true })
  24. .then(() => app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)))
  25. .catch((error) => console.log(error.message));
  26. mongoose.set('useFindAndModify', false);