Tutorialsteacher

Follow Us

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 DatabasesDriverNPM Command
MS SQL Servermssqlnpm install mssql
Oracleoracledbnpm install oracledb
MySQLMySQLnpm install mysql
PostgreSQLpgnpm install pg
SQLitenode-sqlite3npm install node-sqlite

The following table lists important NoSQL databases and respective drives .

NoSQL DatabasesDriverNPM Command
MongoDBmongodbnpm install mongodb
Cassandracassandra-drivernpm install cassandra-driver
LevelDBleveldbnpm install level levelup leveldown
RavenDBravendbnpm install ravendb
Neo4jneo4jnpm install neo4j
Redisredisnpm install redis
CouchDBnanonpm 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.