title: How to run schema creation sql script in mssql with nodejs?
body: <p>I have my code deployed in Azure Function App and using NodeJS I am trying to execute a sql script on SQL Server database. To work this out I have used NPM package <a href="https://www.npmjs.com/package/sqlcmd-runner" rel="nofollow noreferrer">sqlcmd-runner</a>.</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>module.exports.dumpScriptinDatabase = (dbConfig, context) =&gt; {
      return new Promise((resolve, reject) =&gt; {
      sqlcmd({
          server: dbConfig.server,
          database: dbConfig.options.database,
          username: dbConfig.userName,
          password: dbConfig.password,
          encryptedConnection: true,
          inputFiles: [`${__dirname}\\db.sql`]
      })
      .catch((error) =&gt; {
          reject('Error dumping script!!')
      })
      .done(() =&gt; {
          resolve('Dumping script completed.')
      });
  });
  </code></pre>
  
  <p>I am getting all the database details in <code>dbConfig</code> variable. Also <code>db.sql</code> creates the tables, views etc. in the schema.</p>
  
  <p>The issue I am facing is this module never returns me error in case of failure and it also does not executes successfully. The server returns 502 error code on execution.</p>
  
  <p>One thing I am able to debug is that the npm package code uses sqlcmd to execute the script.</p>
  
  <p>Can someone help me on this?</p>