Nodejs

Connect to Snowflake with Node.js Driver

This will be the first entry into my Snowflake toolbox. Today I am going to set my MacBook Pro up to connect to a Snowflake data warehouse via the Snowflake Node.js driver. This could come in handy when needing to move data between systems where direct connections are not available and you need an intermediary. Let’s get started.

This tutorial does require you to have access to a Snowflake data warehouse. If you don’t, you can sign up for a free trial account.

Install Homebrew. I prefer using this method to manage software packages. You can find everything you need on their page, or you can copy and paste:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
 which will get you going right away.

Once Homebrew is installed, you can use it to install any version of Node.js you need. For this example, I decided on v6.14.2 . This version allowed me to maintain some compatibility with other things I plan to use Node for.

 

Install Node.js v6.14.2. At the command prompt enter the following:

$ brew install node@6

This will install the version 6 of Node.js . You can verify this after the install by checking the version with the following command:

$ node -v
v6.14.2

 

Install the snowflake-sdk. With Node installed, you can now use the Node Package Manager (npm) to download and install the snowflake driver.

$ npm install snowflake-sdk

Verify the driver has been installed by confirming the snowflake-sdk subdirectory exists within the node_modules directory.

If things have been successful thus far, we are ready to connect to the Snowflake cloud data warehouse instance via Node.js.

Create a directory

$ mkdir -p snowflake_dev
$ cd snowflake_dev

In this directory, create a file (sfcon.js) by copying and pasting the text below. Remember to use your credentials for account, username, password, and region.

var snowflake = require('snowflake-sdk');
var connection = snowflake.createConnection({
  account: 'account',
  username: 'username',
  password: 'password',
  region: 'region'
});
connection.connect(function(err, conn) {
  if (err) {
    console.error('Unable to connect: ' + err.message);
  } else {
    console.log('Successfully connected as id: ' + connection.getId());
  }
});

You can find detailed information on these parameter values and others in the official Snowflake Documentation for the Node.js driver.

I take Cialis to treat enlarged prostate. Frequent urination spoiled a year of my life. I was getting up five or six times during the night to go to the bathroom. The situation was getting worse and it has almost come to involuntary urination. Everything changed when I started therapy with buy cialis online. I take 5mg pill a day and don’t feel any discomfort.

If you have successfully configured everything, simply run the sfcon.js file using node.

$ node sfcon.js
Successfully connected as id: <connection id>

Look for more posts from me on #SnowflakeDB

Enjoy!

dbaontap Snowflake

 

 

Related Posts Plugin for WordPress, Blogger...

1 Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.