I followed this tutorial to build an exercise tracker <https://www.youtube.com/watch?v=7CqJlxBYj-M>

I tried to use MongoDB Atlas, and I even copied their code word for word but kept getting this error when I typed nodemon server into my terminal: 

```
(node:17960) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms

at new MongooseTimeoutError (C:\Users\bushr\mern-exshr\mern-exercise-tracker\backendercise-tracker\backend\node_modules\mongoose\lib\error\timeout.js:22:11)

at NativeConnection.Connection.openUri (C:\Users\bushr\mern-exercise-tracker\backend\node_modules\mongoose\lib\connection.js:763:19)

at Mongoose.connect (C:\Users\bushr\mern-exercise-tracker\backend\node_modules\mongoose\lib\index.js:332:15)

at Object.<anonymous> (C:\Users\bushr\mern-exercise-tracker\backend\server.js:17:10)0)

at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)

at Module.load (internal/modules/cjs/loader.js:815:32)

at Function.Module._load (internal/modules/cjs/loader.js:727:14)

at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)

at internal/main/run_main_module.js:17:1

(node:17960) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error o originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

```

I then tried to download and run MongoDB locally and my connection to the server was successfully established. However, when I came to use the app I built, I tried to test out the database in Insomnia and post a username, it returns this error:

```
SyntaxError: Unexpected token " in JSON at position 0

```

What do you suggest I start to look out for to solve this? I know I posted two issues, but I'm more keen on solving the latter one so my database starts to store data. I'm not too fussed that I'm using MongoDB locally

Here is my code for the server:

```
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const morgan = require('morgan');
const path = require('path');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 8050;

app.use(cors());
app.use(express.json());

//const uri = 'mongodb+srv://bushra1175:bushy1175@cluster0-7ohm2.gcp.mongodb.net/test?retryWrites=true&w=majority';
mongoose.connect('mongodb://localhost/mern_project', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true

});

const connection = mongoose.connection;
connection.once('open', () => {
    console.log("MongoDB database connection established successfully");
})

const exercisesRouter = require('./routes/exercises');
const usersRouter = require('./routes/users');

app.use('/exercises', exercisesRouter);
app.use('/users', usersRouter);

app.listen(port, () => {
    console.log(`Server is running on port: ${port}`);
});

```

Routes for exercises:

```
const router = require('express').Router();
let Exercise = require('../models/exercise.model');

router.route('/').get((req, res) => {
  Exercise.find()
    .then(exercises => res.json(exercises))
    .catch(err => res.status(400).json('Error: ' + err));
});

router.route('/add').post((req, res) => {
  const username = req.body.username;
  const description = req.body.description;
  const duration = Number(req.body.duration);
  const date = Date.parse(req.body.date);

  const newExercise = new Exercise({
    username,
    description,
    duration,
    date,
  });

  newExercise.save()
  .then(() => res.json('Exercise added!'))
  .catch(err => res.status(400).json('Error: ' + err));
});

router.route('/:id').get((req, res) => {
  Exercise.findById(req.params.id)
    .then(exercise => res.json(exercise))
    .catch(err => res.status(400).json('Error: ' + err));
});

router.route('/:id').delete((req, res) => {
  Exercise.findByIdAndDelete(req.params.id)
    .then(() => res.json('Exercise deleted.'))
    .catch(err => res.status(400).json('Error: ' + err));
});

router.route('/update/:id').post((req, res) => {
  Exercise.findById(req.params.id)
    .then(exercise => {
      exercise.username = req.body.username;
      exercise.description = req.body.description;
      exercise.duration = Number(req.body.duration);
      exercise.date = Date.parse(req.body.date);

      exercise.save()
        .then(() => res.json('Exercise updated!'))
        .catch(err => res.status(400).json('Error: ' + err));
    })
    .catch(err => res.status(400).json('Error: ' + err));
});

module.exports = router;

```

Routes for users:

```
const router = require('express').Router();
let User = require('../models/user.model');

router.route('/').get((req, res) => {
  User.find()
    .then(users => res.json(users))
    .catch(err => res.status(400).json('Error: ' + err));
});

router.route('/add').post((req, res) => {
  const username = req.body.username;

  const newUser = new User({username});

  newUser.save()
    .then(() => res.json('User added!'))
    .catch(err => res.status(400).json('Error: ' + err));
});

module.exports = router;

```