Node js connection with Snowflake could come in handy while moving data between systems where direct connections are not available and an intermediary is required. Node.js is a run-time environment that includes everything required to execute a program written in JavaScript. It is used for running scripts on the server to render content before it is delivered to a web browser. NPM stands for Node Package Manager, which is an application and repository for developing and sharing JavaScript codes.
Let’s get started! For this connection, you’ll require to have access to a Snowflake data warehouse. If you don’t, you can sign up for a free trial account. Written in pure JavaScript, the Node.js driver provides a native asynchronous Node.js interface to Snowflake.The typical workflow for using the driver is:
- Establish a connection with Snowflake
- Execute statements, e.g. queries and DDL/DML commands
- Consume the results
- Terminate the connection
Refer to the following steps to establish the connection:
Step 1: Install Node.js
Node.js must already be installed in the environment where you require installing the driver. You can verify this after the installation, by checking the version using the following command:
Click here to know more about installation.
Step 2: Install the Snowflake-sdk
After Node installation, you can now use the Node Package Manager (npm) to download and install the Snowflake driver. The command downloads and installs the Snowflake Node.js driver.
Step 3: Connect the Snowflake Cloud Data Warehouse
If things have been successful thus far, we are now ready to connect to the Snowflake cloud data warehouse instance via Node.js. Create a directory with the following commands:
Step 4: Create a File
In this directory, create a file (app.js) by copy-pasting the following text. Remember to use your credentials for account, username, password, and region.
Step 5: Run the File
Open the terminal window and run the file(app.js) with the following command to create the connection:
The node js Snowflake connection is successfully created.