Create a TCP connection when using Node.js

Demonstrates opening a TCP connection to Cloud SQL for SQL Server using the Node.js mssql module.

Code sample

Node.js

const createPool = async () => {
  const config = {pool: {}, options: {}};
  config.user = process.env.DB_USER; // e.g. 'my-db-user'
  config.password = process.env.DB_PASS; // e.g. 'my-db-password'
  config.database = process.env.DB_NAME; // e.g. 'my-database'
  // set the server to '172.17.0.1' when connecting from App Engine Flex
  config.server = process.env.DEPLOYED ? '172.17.0.1' : '127.0.0.1';
  config.port = 1433;

  // ...
  config.options.trustServerCertificate = true;
  return await mssql.connect(config);
};

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.