title: Cannot read property 'id' of undefined when posting to local API
body: <p>This is my first time building an API and I seem to be having an issue with post/put requests. Get works as expected. When I try to POST to the api I get and error that says </p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'id' of undefined
        at Object.addUser (D:\github\DC-API\models\user.js:11:58)</p>
  </blockquote>
  
  <p>Here is my code.</p>
  
  <p>user.js </p>
  
  <pre><code>var db = require('../dbconnection');
  
  var User = {  
    getAllUsers: function(callback) {  
      return db.query("select * from users", callback);  
    },  
    getUserById: function(id, callback) {  
      return db.query("select * from users where Id=?", [id], callback);
    },  
    addUser: function(User, callback) {  
      return db.query("Insert into users values(?,?,?)", [User.id, User.username, User.avatar], callback);  
    },  
    deleteUser: function(id, callback) {  
      return db.query("delete from users where Id=?", [id], callback);  
    },  
    updateUser: function(id, User, callback) {  
      return db.query("update users set username=?,avatar=? where Id=?", [User.username, User.avatar, id], callback);  
    }  
  };  
  module.exports = User;
  </code></pre>
  
  <p>users.js</p>
  
  <pre><code>var express = require('express');  
  var router = express.Router();  
  var User = require('../models/user');
  
  router.get('/:id?', function(req, res, next) {  
    if (req.params.id) {  
      User.getUserById(req.params.id, function(err, rows) {  
        if (err) {  
          res.json(err);  
        } else {  
          res.json(rows);  
        }  
      });  
    } else {  
      User.getAllUsers(function(err, rows) {  
        if (err) {  
          res.json(err);  
        } else {  
          res.json(rows);  
        }  
      });  
    }  
  });  
  router.post('/', function(req, res, next) {  
    User.addUser(req.body, function(err, count) {  
      if (err) {  
        res.json(err);  
      } else {  
        res.json(req.body); //or return count for 1 &amp; 0  
      }  
    });  
  });  
  router.delete('/:id', function(req, res, next) {  
    User.deleteUser(req.params.id, function(err, count) {  
      if (err) {  
        res.json(err);  
      } else {  
        res.json(count);  
      }  
    });  
  });  
  router.put('/:id', function(req, res, next) {  
    User.updateUser(req.params.id, req.body, function(err, rows) {  
      if (err) {  
        res.json(err);  
      } else {  
        res.json(rows);  
      }  
    });  
  });  
  module.exports = router;
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>var createError = require('http-errors');
  var express = require('express');
  var path = require('path');
  var cookieParser = require('cookie-parser');
  var logger = require('morgan');
  
  var indexRouter = require('./routes/index');
  var usersRouter = require('./routes/users');
  
  var app = express();
  var cors=require('cors');
  var Users=require('./routes/users');
  
  app.use(cors());
  app.use('/users',usersRouter);
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    next(createError(404));
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  module.exports = app;
  </code></pre>
  
  <p>I am using Postman to test the api and I am sending data through the body with both form-data and raw json. Like I said before this is the first time I am building an API so it could very well be a simple oversight. Thanks for the help in advance.</p>