title: REST API new users not posting to MongoDB
body: <p>I am new to building REST API's, and I am trying to enter new user information into a collection called 'Users', however, when I submit the information I get <code>Cannot POST /register</code> </p>
  
  <p>Below is my code</p>
  
  <p>server.js </p>
  
  <pre><code>require('dotenv').config()
  
  const express = require('express') 
  const app = express()
  const mongoose = require('mongoose')
  const expressValidator = require('express-validator')
  
  
  mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true , useUnifiedTopology: true })
  const db = mongoose.connection
  db.on('error', (error) =&gt; console.error(error))
  db.once('open', () =&gt; console.log('Connected to Database'))
  
  app.use(express.json())
  
  const articlesRouter = require('./routes/articles')
  app.use('/articles', articlesRouter)
  
  const userRouter = require('./routes/users')
  app.use('/register', userRouter)
  
  app.set('view-engine', 'ejs')
  app.use(express.urlencoded({ extended: false }))
  
  app.get('/', (req, res) =&gt; {
      res.render('index.ejs')
  })
  
  app.get('/login', (req, res) =&gt; {
      res.render('login.ejs')
  })
  
  app.post('/login', (req, res) =&gt; {
  
  })
  
  app.get('/register', (req, res) =&gt; {
      res.render('register.ejs')
  })
  
  app.listen(3000, () =&gt; console.log('Server Started'))
  </code></pre>
  
  <p>Users model</p>
  
  <pre><code>const mongoose = require('mongoose')
  const bcrypt = require('bcrypt')
  
  var userSchema = new mongoose.Schema({
      firstName: String, 
      lastName: String, 
      email: String, 
      password: String, 
      permissionLevel: Number, 
      created: Date}, 
      { collection: 'Users'});
  
      module.exports = mongoose.model('Users', userSchema);
  
  module.exports.createUser = function(newUser, callback){
      bcrypt.genSalt(10, function(err, salt) {
          bcrypt.hash(newUser.password, salt, function(err, hash) {
              newUser.password = hash;
              newUser.save(callback);
          });
      });
  }
  
  module.exports.getUserByEmail = function(email, callback){
      var query = {email: email};
      User.findOne(query, callback);
  }
  
  module.exports.getUserById = function(id, callback){
      user.findById(id, callback);
  }
  
  module.exports.comparePassword = function(candidatePassword, hash, callback) {
      bcrypt.compare(candidatePassword, hash, function(err, isMatch){
          if(err) throw err;
          callback(null, isMatch)
      });
  }
  </code></pre>
  
  <p>users routes</p>
  
  <pre><code>const express = require('express')
  const router = express.Router()
  const Users = require('../models/users')
  const passport = require('passport')
  const LocalStrategy = require('passport-local').Strategy
  
  //Register Page - GET
  router.get('/register', (req, res) =&gt; {
      res.render('register.hbs', {
          pageTitle: 'register'
      });
  });
  
  //Login Page - GET
  router.get('/login', (req, res) =&gt; {
      res.render('login.hbs', {
          pageTitle: 'login'
      });
  });
  
  //Register - POST
  router.post('/', (req, res) =&gt; {
      var firstName = req.body.firstName;
      var lastName = req.body.lastName;
      var email = req.body.email;
      var password = req.body.password;
  
      //validations
      req.checkBody('firstName', 'Your First Name is Required').notEmpty();
      req.checkBody('lastName', 'Your Last Name is Required').notEmpty();
      req.checkBody('email', 'A valid email is required').isEmail();
      req.checkBody('password', 'An Account Passowrd Is Required').notEmpty();
  
      var errors = req.validationErrors();
      if (errors) {
          res.render('register', {
              errors:errors 
          });
      } else {
          var newUser = new newUser({
              firstName: firstName,
              lastName: lastName,
              email: email,
              password: password,
          });
  
          User.createUser(newUser, function(err, user) {
              if(err) throw(err);
              console.log(user);
          });
  
          req.flash('success_message', "You are now registered!");
          res.redirect('/login');
      }
  });
  
  passport.use(new LocalStrategy({
      email: 'email'
  },
  function(email, password, done){
      Users.getUserByEmail(email, function(err, Users){
          if(err) throw err;
          if(!Users){
              return done(null, false, {message: 'Unknown Email Address'});
          }
  
          Users.comparePassword(password, user.password, function(err, ismatch){
              if(err) throw err;
              if(ismatch){
                  return done (null, user); 
              } else {
                  return done(null, false, {message: 'Invalid Passowrd'});
              }
          });
      });
  }));
  
  passport.serializeUser(function(user, done){
      done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done) {
      Users.getUserByID(id, function(err, user) {
          done(err, user) 
      });
  }); 
  
  router.post('/login', passport.authenticate('local', {
      successRedirect: '/dashboard',
      failureRedirect: '/login',
      successFlash: 'Welcome',
      failureFlash: 'Invalid Email or Passowrd!'
  }), function(req, res) {
      res.redirect('/');
  });
  
  router.get('/logout', function(req, res) {
      req.logout();
      req.flash('Success_message', 'You are now logged out!')
      res.redirect('/');
  });
  
  module.exports = router 
  </code></pre>
  
  <p>I suspect the conflict is between the router /register and the my 'Users' collection. I'm just unable to pinpoint what the issue could be. </p>
  
  <p>Any help would be greatly appreciated</p>