← Node.js & Express learning path
Node.js & Express · Module 8 of 10

Databases with Node

Store data in MongoDB or SQL databases from Express.

📖 Key ideas

  1. MongoDB with Mongoose: schemas and models.
  2. SQL (PostgreSQL/MySQL) with pg, mysql2 or an ORM like Prisma.
  3. Keep connection strings in environment variables.
  4. Use parameterised queries to avoid SQL injection.
  5. Handle database errors and return clean messages.
💡 Real-life example: An ORM is a translator: you speak JavaScript, it speaks SQL to the database.
MongooseMongoDB modelling library
PrismaType-safe ORM
Parameterised queryQuery with placeholders for values
Connection stringURL with database credentials