title: store data from node.js to sql database
body: <p>I am trying to store result data received from client side into sql database, however I am getting these errors</p>
  
  <blockquote>
    <ol>
    <li>TypeError: request.query(...).then is not a function</li>
    <li>TypeError: callback is not a function</li>
    </ol>
  </blockquote>
  
  <p>I am quite new to node.js and sql database. I spent quite a bit of time to figure these but not sure where to start,,
  I tried to remove .then, it works fine but still throws 2nd error. Can anyone please advice on this problem?</p>
  
  <p><strong>node.js</strong></p>
  
  <pre><code>//Receive from Angular Server 
  const express = require('express');
  const bodyParser = require('body-parser');
  const app = express();
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  app.all("/*", function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
    next();
  });
  
  app.listen(1433, function () { console.log('Example app listening on port 1433!') })
  
  var sql = require('mssql');
  var config = {
    server: "",
    database: "",
    user: "",
    password: "",
    port: 
  };
  
  
  app.post('/ping', function (req, res) {
    res.send(res.body);
    var jsondata = JSON.stringify(req.body);
    var test = JSON.parse(jsondata);
  
    var values = [];
    values.push(test.GradeA, test.GradeB, test.GradeC)
    console.log(values);
    //values = [ '25', '36', '32' ] 
  
      var dbConn = new sql.Connection(config);
      dbConn.connect().then(function () {
        var transaction = new sql.Transaction(dbConn);
  
        transaction.begin().then(function () {
          var request = new sql.Request(transaction);
  
          request.query("INSERT INTO RMS (GradeA, GradeB, GradeC) values VALUES ? ", [values])
            .then(function () {
              transaction.commit().then(function (recordSet) {
                console.log('Rows Affected :' + request.rowsAffected);
                dbConn.close();
  
              }).catch(function (err) {
  
                console.log("Error in Transaction Commit" + err);
                dbConn.close();
              });
            }).catch(function (err) {
  
              console.log("Error in Transaction Begin" + err);
              dbConn.close();
            });
  
        }).catch(function (err) {
  
          console.log(err);
          dbConn.close();
        });
      }).catch(function (err) {
  
        console.log(err);
      });
    });
  </code></pre>