Data Access in Node.js

Node.js supports all kinds of databases no matter if it is a relational database or NoSQL database. However, NoSQL databases like MongoDb are the best fit with Node.js.

To access the database from Node.js, you first need to install drivers for the database you want to use.

The following table lists important relational databases and respective drivers.

Relational Databases Driver NPM Command
MS SQL Server mssql npm install mssql
Oracle oracledb npm install oracledb
MySQL MySQL npm install mysql
PostgreSQL pg npm install pg
SQLite node-sqlite3 npm install node-sqlite

The following table lists important NoSQL databases and respective drives .

NoSQL Databases Driver NPM Command
MongoDB mongodb npm install mongodb
Cassandra cassandra-driver npm install cassandra-driver
LevelDB leveldb npm install level levelup leveldown
RavenDB ravendb npm install ravendb
Neo4j neo4j npm install neo4j
Redis redis npm install redis
CouchDB nano npm install nano
The above database list is not limited. There are many other databases and drivers available to be used with Node.js. Also, there are many drivers available for each database. So, choose a driver carefully based on your need.

Learn how to access MS SQL Server and MongoDB databases in the next section.