Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snowflake - how to connect to Snowflake using NodeJS

Does anyone has a working code to connect NodeJS and Snowflake.

Tried following instructions for NodeJS:

var snowflake = require('snowflake-sdk');

var connection = snowflake.createConnection({
  account: 'account1',
  username: 'user1',
  password: 'pass1',
  region: 'us-east-1'
});

connection.connect(function(err, conn) {
  if (err) {
    console.error('Unable to connect: ' + err.message);
  } else {
    console.log('Successfully connected as id: ' + connection.getId());
  }
});

Keep getting errors:

Network error. Could not reach Snowflake.

Similarly - following instructions for Python works without problem (using EXACT same user/pass/account etc. as for NodeJS):

import snowflake.connector

ctx = snowflake.connector.connect(
    user='user1', 
    password='pass1',
    account='account1'
)

print ("SELECT current_version():")
cs = ctx.cursor()
try:
    cs.execute("SELECT current_version()")
    one = cs.fetchone()
    print(one[0])  # 2.50.2
finally:
    cs.close()
like image 248
Joe Avatar asked Sep 18 '25 19:09

Joe


1 Answers

The account that use in python has "account_id.region" something like

ctx = snowflake.connector.connect(
user='user1', 
password='pass1',
account='abc.us-east-1'
)

For node.js you need to give the same as:

var connection = snowflake.createConnection({
  account: 'abc',
  username: 'user1',
  password: 'pass1',
  region: 'us-east-1'
});
like image 133
Aneesha Avatar answered Sep 21 '25 08:09

Aneesha