error: POST http://localhost:3000/api/createProductCategory 500 (Internal Server Error)
<p>I am trying to insert data into a table using POST method for that I have a angular service function</p>

<pre><code>angular.module("productCategoryModule")
.factory("productCategoryService",productCategoryService);

productCategoryService.$inject = ['$http'];

function productCategoryService($http){
    return {
        createProductCategory:function(productCategory){
            console.log("createProductCategory in service called",productCategory);
            return $http.post('/api/createProductCategory',
                {
                    categoryName:productCategory.categoryName,
                    details:productCategory.categoryDetails
                }
            );
        },
        getAllProductCategories:function(){
            return $http.get('/api/getAllProductCategory');
        }
    }
}
</code></pre>

<p>and at server side I have</p>

<pre><code>function productCategoryRouteConfig(app){
    this.app = app;
    this.routeTable = [];
    this.init();
}

productCategoryRouteConfig.prototype.init = function(){
    var self = this;
    this.addRoutes();
    this.processRoutes();
}

productCategoryRouteConfig.prototype.processRoutes = function(){
    var self = this;
    self.routeTable.forEach(function(route){
        if(route.requestType == 'get'){
            //console.log("requestType",route.requestType)
            self.app.get(route.requestUrl,route.callbackFunction);
        } else if(route.requestType == 'post'){
            //console.log("requestType",route.requestType);
            self.app.post(route.requestUrl,route.callbackFunction);
        } else if(route.requestType == 'delete'){

        }

    });
}

productCategoryRouteConfig.prototype.addRoutes = function(){
    var self = this;
    self.routeTable.push({
        requestType: 'get',
        requestUrl: '/createProductCategory',
        callbackFunction: function(req, res){
            res.render('createProductCategory',{title:'Create Product Category'});
        }
    });

    self.routeTable.push({
        requestType: 'post',
        requestUrl: '/api/createProductCategory',
        callbackFunction: function(req, res){
            console.log("Post called");
            //res.render('createProductCategory');
            console.log("req.body",req.body);
            var productCategoryDb = require('../database/productCategoryDb');
            // console.log("productCategoryDb post",productCategoryDb);
            // console.log("hello from createProductCategory post");
            // console.log("req.body",req.body);

            // productCategoryDb.productCategoryDb.createProductCategory(req.body, function(status){
            //  if(status)
            //      res.json(status);
            //  console.log(status);
            // });
        }
    });

    self.routeTable.push({
        requestType: 'get',
        requestUrl: '/viewProductCategory',
        callbackFunction: function(req, res){
            res.render('viewProductCategory',{title:'View Product Category'});
        }
    });

    self.routeTable.push({
        requestType: 'get',
        requestUrl: '/api/getAllProductCategory',
        callbackFunction: function(req, res){
            console.log("hello from getAllProductCategory");
            var productCategoryDb = require('../database/productCategoryDb');
            console.log("productCategoryDb",productCategoryDb);
            // productCategoryDb.productCategoryDb.getAllProductCategories(
            //  function (productCategories){
            //      console.log("productCategories",productCategories);
            //      res.json({productCategories : productCategories});
            //  }
            // );
        }
    });
}

module.exports = productCategoryRouteConfig;
</code></pre>

<p>when I click on the button on client side I get this error</p>

<p><strong>POST <a href="http://localhost:3000/api/createProductCategory" rel="nofollow">http://localhost:3000/api/createProductCategory</a> 500 (Internal Server Error)</strong></p>

<p>I am using Node express mysql and angular.</p>

<p>There are three files in me database folder.</p>

<p>1.connectionString.js</p>

<pre><code>var mysqlConnectionString = {
    connectionString:{
        host:'localhost',
        user:'root',
        password:'root',
        database:'vidzy'
    }
}

//module.exports = mysqlConnectionString;
exports.mysqlConnectionString = mysqlConnectionString;
</code></pre>

<p>2.connection.js</p>

<pre><code>var mysql = require('mysql');
var mysqlConnectionString = require('/home/ep-3/node-express/yt_tutorial/database/connectionString.js');
var connectionStringProvider = {
    getSqlConnection:function(){
        var connection = mysql.createConnection(mysqlConnectionString.mysqlConnectionString.connectionString);

        connection.connect(function(err){
            if(err){
                throw err;
            } else{
                console.log("connection was successful");
            }
        });

        return connection;
    },
    closeSqlConnection:function(currentConnection){
        currentConnection.end(function(err){
            if(err){
                throw err;
            } else{
                console.log("Disconnected");
            }
        })
    }
}

exports.connectionStringProvider = connectionStringProvider;
</code></pre>

<p>3.productCategoryDb.js</p>

<pre><code>var connectionProvider = require('/home/ep-3/node-express/yt_tutorial/database/connection.js');
var productCategoryDb = {

    createProductCategory : function(productCategory, onSuccessful){

        var insertStatement = 'INSERT INTO productcategory SET?';

        var category = {
            categoryName : productCategory.categoryName,
            Details : productCategory.details,
            isValid : productCategory.isValid,
            CreatedDate : new Date()
        }

        var connection = connectionProvider.connectionStringProvider.getSqlConnection();

        if(connection){

            connection.query(insertStatement, category, function(err, result){

                if(err){

                    console.log(err);
                }

                onSuccessful({status : 'Successful'});
                console.log(result); 
            });

            connectionProvider.connectionStringProvider.closeSqlConnection(connection);
        }
    },

    getAllProductCategory : function(callback){
        var connection = connectionProvider.connectionStringProvider.getSqlConnection();
        var selectStatement = 'SELECT * FROM productcategory';

        if(connection){
            connection.query(selectStatement, function(err, rows, fields){
                if(err){ through err; }
                console.log(rows);
                callback(rows);
            });
        }
    }
}

exports.productCategoryDb = productCategoryDb;
</code></pre>