title: NodeJS to SQL Server Connection not working: socket hang up issue
body: <p>Here is my complete code for sql connection, all code I have got from stackoverflow issues.
  Everywhere, I found the same code is being suggested, hence I also tried with the same.
  I have some other application which uses same connection with NextJs and it works fine, however, If I try only with NodeJS code, it gives some socket hang up error (code:'ESOCKET' name:'ConnectionError').
  Please make a note that TCP is already configured on remote server and its working fine with other applications.</p>
  <p>Any help is appreciated, thank you.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const express = require('express');
  const fs = require('fs');
  const path = require('path');
  const cheerio = require("cheerio");
  const sql = require('mssql');
  
  require('dotenv').config(); //to use the env variables
  
  // config for your database
  var config = {
      user: process.env.DATABASE_USER,
      password: process.env.DATABASE_PASSWORD,
      server: process.env.DATABASE_HOST,
      database: process.env.SOMEDB,
      port: 14345, // process.env.DATABASE_PORT,
      options: {
          encrypt: true, // for azure
          trustServerCertificate: false // change to true for local dev / self-signed certs
      }
  };
  
          // make sure that any items are correctly URL encoded in the connection string
          let appPool = new sql.ConnectionPool(config);
          
          //I got error on below connect
          sql.connect(config).then(function(pool) {
              //It never reaches here, it directly goes to the catch block
              app.locals.db = pool;
              const server = app.listen(3000, function () {
                const host = server.address().address
                const port = server.address().port
                console.log('Example app listening at http://%s:%s', host, port)
              })
            }).catch(function(err) {
              console.error('Error creating connection pool', err)
            });</code></pre>
  </div>
  </div>
  </p>