简体   繁体   中英

How to connect to snowflake using node.js

I am trying to connect my API to snowflake, using the node.js driver found in the snowflake documentationhttps://docs.snowflake.com/en/user-guide/nodejs-driver-use.html

const connection = snowflake.createConnection({
  account: process.env.SNOWFLAKE_ACCOUNT,
  username: process.env.SNOWFLAKE_USERNAME,
  password: process.env.SNOWFLAKE_PASSWORD,
})

connection.connect((err, conn) => {
  if (err) {
    console.error('Unable to connect: ' + err.message);
  } 
  else {
    console.log('Successfully connected to Snowflake.');
    const connection_ID = conn.getId();
    return connection_ID
  }
});

However, I am getting this error: Unable to connect: Network error. Could not reach Snowflake. Unable to connect: Network error. Could not reach Snowflake.

What am I missing?

I'd recommend double checking what you have for SNOWACCT make sure it's set like the examples in https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#required-connection-options

The next thing I'd do is try to see if I could get SnowCD installed on the host(client) your node.js application is running from. SnowCD should help you determine what http/https resources you can't access, and then perhaps you can work with someone on your networking team to determine why your access isn't allowed (proxies, VPC rules, etc.). https://docs.snowflake.com/en/user-guide/snowcd.html

If you cannot install SnowCD, you can try to emulate the things it does, for example:

See my answer on https://stackoverflow.com/a/65434455/1440712

Make sure your account is something like this xxx.us-east-1 , region is now deprecated.

If you want to connect a snowflake with node js, You must install

"snowflake-sdk"

using npm. the below code will help you to access snowflake connection.

const snowflake = require('snowflake-sdk');       
   connection = snowflake.createConnection({
      "account": "your account",
      "username": "user name",
      "password": "password",
      "database": "snowflake db",
      "warehouse": "snowflake warehouse",
      "schema": "schema"
    });connection.connect(function (err, conn) {
    if (err) {
      console.error('Unable to connect: ' + err.message);
    } else {
      console.log('Successfully connected as id: ' + connection.getId());
    }
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM