🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@google-cloud/cloud-sql-connector

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/cloud-sql-connector

A JavaScript library for connecting securely to your Cloud SQL instances

1.8.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created

What is @google-cloud/cloud-sql-connector?

@google-cloud/cloud-sql-connector is an npm package that simplifies the process of connecting to Google Cloud SQL instances from Node.js applications. It provides secure and efficient connection management, handling the complexities of authentication and connection pooling.

What are @google-cloud/cloud-sql-connector's main functionalities?

Connecting to a Cloud SQL instance

This feature allows you to connect to a Google Cloud SQL instance using the Cloud SQL Connector. It handles the authentication and connection details, providing a seamless way to connect to your database.

const { CloudSQLConnector } = require('@google-cloud/cloud-sql-connector');
const mysql = require('mysql2/promise');

async function connectToCloudSQL() {
  const connector = new CloudSQLConnector();
  const clientOpts = await connector.getOptions({
    instanceConnectionName: 'project:region:instance',
    user: 'my-user',
    password: 'my-password',
    database: 'my-database'
  });

  const connection = await mysql.createConnection(clientOpts);
  console.log('Connected to Cloud SQL');
  return connection;
}

connectToCloudSQL().catch(console.error);

Connection Pooling

This feature demonstrates how to create a connection pool using the Cloud SQL Connector. Connection pooling helps manage multiple database connections efficiently, improving performance and resource utilization.

const { CloudSQLConnector } = require('@google-cloud/cloud-sql-connector');
const mysql = require('mysql2/promise');
const { createPool } = require('mysql2/promise');

async function createConnectionPool() {
  const connector = new CloudSQLConnector();
  const clientOpts = await connector.getOptions({
    instanceConnectionName: 'project:region:instance',
    user: 'my-user',
    password: 'my-password',
    database: 'my-database'
  });

  const pool = createPool({
    ...clientOpts,
    connectionLimit: 10
  });

  console.log('Connection pool created');
  return pool;
}

createConnectionPool().catch(console.error);

Other packages similar to @google-cloud/cloud-sql-connector

Keywords

connector

FAQs

Package last updated on 28 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts