title: Node Express - Cannot POST / error
body: <p>I have been following a tutorial on how to build a full stack MEAN application and everything has been functioning fine up until this point (registration, login and authentication.) </p>
  
  <p>I'm now trying to do a post request for the blog page and am receiving the following error:</p>
  
  <pre><code>&lt;pre&gt;Cannot POST /blogs/newBlog&lt;/pre&gt;
  </code></pre>
  
  <p>All that I've done so far is create a schema, a route and then made the relevant changes to index.js. The schema file provided below is the one provided by the author of the tutorial in his respository (unlike the other two files it is in it's completed form.) The problem still persists and so I do not believe it to be the problem.</p>
  
  <p><strong>Blog schema:</strong></p>
  
  <pre><code>/* ===================
     Import Node Modules
  =================== */
  const mongoose = require('mongoose'); // Node Tool for MongoDB
  mongoose.Promise = global.Promise; // Configure Mongoose Promises
  const Schema = mongoose.Schema; // Import Schema from Mongoose
  
  // Validate Function to check blog title length
  let titleLengthChecker = (title) =&gt; {
    // Check if blog title exists
    if (!title) {
      return false; // Return error
    } else {
      // Check the length of title
      if (title.length &lt; 5 || title.length &gt; 50) {
        return false; // Return error if not within proper length
      } else {
        return true; // Return as valid title
      }
    }
  };
  
  // Validate Function to check if valid title format
  let alphaNumericTitleChecker = (title) =&gt; {
    // Check if title exists
    if (!title) {
      return false; // Return error
    } else {
      // Regular expression to test for a valid title
      const regExp = new RegExp(/^[a-zA-Z0-9 ]+$/);
      return regExp.test(title); // Return regular expression test results (true or false)
    }
  };
  
  // Array of Title Validators
  const titleValidators = [
    // First Title Validator
    {
      validator: titleLengthChecker,
      message: 'Title must be more than 5 characters but no more than 50'
    },
    // Second Title Validator
    {
      validator: alphaNumericTitleChecker,
      message: 'Title must be alphanumeric'
    }
  ];
  
  // Validate Function to check body length
  let bodyLengthChecker = (body) =&gt; {
    // Check if body exists
    if (!body) {
      return false; // Return error
    } else {
      // Check length of body
      if (body.length &lt; 5 || body.length &gt; 500) {
        return false; // Return error if does not meet length requirement
      } else {
        return true; // Return as valid body
      }
    }
  };
  
  // Array of Body validators
  const bodyValidators = [
    // First Body validator
    {
      validator: bodyLengthChecker,
      message: 'Body must be more than 5 characters but no more than 500.'
    }
  ];
  
  // Validate Function to check comment length
  let commentLengthChecker = (comment) =&gt; {
    // Check if comment exists
    if (!comment[0]) {
      return false; // Return error
    } else {
      // Check comment length
      if (comment[0].length &lt; 1 || comment[0].length &gt; 200) {
        return false; // Return error if comment length requirement is not met
      } else {
        return true; // Return comment as valid
      }
    }
  };
  
  // Array of Comment validators
  const commentValidators = [
    // First comment validator
    {
      validator: commentLengthChecker,
      message: 'Comments may not exceed 200 characters.'
    }
  ];
  
  // Blog Model Definition
  const blogSchema = new Schema({
    title: { type: String, required: true, validate: titleValidators },
    body: { type: String, required: true, validate: bodyValidators },
    createdBy: { type: String },
    createdAt: { type: Date, default: Date.now() },
    likes: { type: Number, default: 0 },
    likedBy: { type: Array },
    dislikes: { type: Number, default: 0 },
    dislikedBy: { type: Array },
    comments: [{
      comment: { type: String, validate: commentValidators },
      commentator: { type: String }
    }]
  });
  
  // Export Module/Schema
  module.exports = mongoose.model('Blog', blogSchema);
  </code></pre>
  
  <p><strong>routes/blogs.js</strong></p>
  
  <pre><code>const User = require('../models/user'); // Import User Model Schema
  const jwt = require('jsonwebtoken');
  const config = require('../config/database');
  
  module.exports = (router) =&gt; {
  
    router.post('/newBlog', (req, res) =&gt; { // TODO: change URL
      res.send('test worked');
    });
  
    return router; // Return router object to main index.js
  }
  </code></pre>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>/* ===================
     Import Node Modules
  =================== */
  const env = require('./env');
  const express = require('express');
  const app = express();
  const router = express.Router();
  const mongoose = require('mongoose');
  mongoose.Promise = global.Promise;
  const config = require('./config/database');
  const path = require('path');
  const authentication = require('./routes/authentication')(router);
  const blogs = require('./routes/blogs')(router);
  const bodyParser = require('body-parser');
  const cors = require('cors'); 
  
  const port = process.env.PORT || 8080;
  
  // Database Connection
  mongoose.connect(config.uri, {
    useMongoClient: true,
  }, (err) =&gt; {
    // Check if database was able to connect
    if (err) {
      console.log('Could NOT connect to database: ', err);
   message
    } else {
      console.log('Connected to ' + config.db);
    }
  });
  
  // Middleware
  app.use(cors({ origin: 'http://localhost:4200' }));
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(express.static(__dirname + '/public'));
  app.use('/authentication', authentication);
  app.use('/blogs', blogs);
  
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.join(__dirname + '/public/index.html'));
  });
  
  // Start Server: Listen on port 8080
  app.listen(port, () =&gt; {
    console.log('Listening on port ' + port + ' in ' + process.env.NODE_ENV + ' mode');
  });
  </code></pre>
  
  <p>I have been enjoying this course greatly and would appreciate any help (even if it is to simply rule out possible causes.)</p>
  
  <p><strong>Error in full:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Error&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;pre&gt;Cannot POST /blogs/newBlog&lt;/pre&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>