Sobes.tech
Junior — Middle

Milliseid tööriistu või teeke kasutasite andmebaasidega suhtlemise protsessis?

sobes.tech AI

Vastus AI-lt

In Node.js, the following tools and libraries are commonly used for interacting with databases:

  • Sequelize — ORM for SQL databases (PostgreSQL, MySQL, SQLite, etc.), allows working with models and migrations.
  • TypeORM — another popular ORM with support for TypeScript.
  • Mongoose — ODM for MongoDB, useful for working with document-based databases.
  • Knex.js — SQL query builder, which can be used as an alternative to ORM.
  • node-postgres (pg) — native client for PostgreSQL.

Example of connecting to MongoDB using Mongoose:

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mydb', { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() => console.log('Connected to MongoDB'))
  .catch(err => console.error('Connection error', err));

The choice of tool depends on the type of database and project requirements.