🌍 NodeJS · flashcards
NodeJS Database Integration Flashcards
50 question-and-answer cards covering Database Integration as it is examined in NodeJS. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Database Integration deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
What is the standard Node.js library for connecting to PostgreSQL?
The 'pg' package (node-postgres). It provides a Client for single connections and a Pool for pooled connections, both with a Promise-based query API.
How does the 'pg' driver denote parameter placeholders, and how does this differ from mysql2?
pg uses numbered placeholders $1, $2, $3, ... (e.g., SELECT * FROM users WHERE id = $1). mysql2 uses positional ? placeholders instead.
What is the JSONB type in PostgreSQL, and how does it differ from JSON?
JSONB stores JSON in a decomposed binary format that is faster to query and supports indexing (e.g., GIN indexes), but slightly slower to write. The JSON type stores the exact text and is faster to insert but slower to process.
What does ACID stand for in relational databases?
Atomicity, Consistency, Isolation, Durability — the four guarantees that ensure reliable database transactions.
What is Sequelize?
Sequelize is a promise-based Node.js ORM that supports PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server. It maps JavaScript models/classes to SQL tables and provides methods for CRUD, associations, migrations, and transactions.
Which SQL databases (dialects) does Sequelize support?
PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (MSSQL), and Snowflake/Db2 (via dialects). It does NOT support MongoDB — that is the domain of an ODM like Mongoose.
In Sequelize, what is a Model and how do you define one?
A Model is a class representing a table, defined via sequelize.define('Name', { field: { type, ... } }) or by extending Model and calling Model.init(). Each attribute maps to a table column with a Sequelize DataType.
By default, what two timestamp columns does Sequelize automatically add to a model, and how do you disable them?
createdAt and updatedAt. Disable them by setting { timestamps: false } in the model options.
What are the four association types in Sequelize?
belongsTo (one-to-one owner side / many-to-one), hasOne (one-to-one), hasMany (one-to-many), and belongsToMany (many-to-many, using a junction table).
In Sequelize, how do you create and how do you fetch records (CRUD read/create)?
Create: Model.create({...}) or build() + save(). Read: Model.findAll(), Model.findOne({ where }), Model.findByPk(id). Update: Model.update({...}, { where }). Delete: Model.destroy({ where }).
What does sequelize.sync() do, and what does { force: true } vs { alter: true } mean?
sync() creates tables from model definitions if they don't exist. { force: true } drops and recreates each table (data loss). { alter: true } modifies existing tables to match the models without dropping them.
What is a Sequelize migration, and why is it preferred over sync() in production?
A migration is a versioned, reversible script (up/down) describing schema changes, run via the Sequelize CLI. It gives controlled, trackable schema evolution and avoids the data loss and unpredictability of sync({ force/alter }) in production.
What is a database transaction, and how do you use one in Sequelize?
A transaction groups multiple operations so they all succeed or all roll back (atomicity). In Sequelize: const t = await sequelize.transaction(); pass { transaction: t } to each query; then await t.commit() or await t.rollback().
What is the N+1 query problem, and how does Sequelize's 'eager loading' address it?
N+1 occurs when fetching N parent rows then issuing 1 extra query per parent for related data ($1 + N$ queries). Eager loading via the include option performs a JOIN to fetch parents and their associations in a single query.
In SQL, what is the difference between an INNER JOIN and a LEFT (OUTER) JOIN?
INNER JOIN returns only rows with matching keys in both tables. LEFT JOIN returns all rows from the left table plus matched rows from the right, filling unmatched right-side columns with NULL.
What is a primary key versus a foreign key in a relational database?
A primary key uniquely identifies each row in a table and cannot be NULL. A foreign key is a column referencing the primary key of another table, enforcing referential integrity between them.
What is database normalization, and what problems does it solve?
Normalization organizes tables to reduce data redundancy and improve integrity by splitting data into related tables (e.g., 1NF, 2NF, 3NF). It prevents insertion, update, and deletion anomalies.
Give the core conceptual difference between SQL and NoSQL databases relevant to choosing MongoDB vs PostgreSQL.
SQL (Postgres/MySQL): structured, fixed schema, tables with relations, strong ACID, best for complex queries/joins and structured data. NoSQL (MongoDB): flexible schema, document-based, horizontally scalable, best for unstructured/evolving data and high write throughput.
What is an index in a database, and what is its main trade-off?
An index is a data structure (often a B-tree) that speeds up read/lookup queries on indexed columns/fields. Trade-off: it consumes extra storage and slows down writes (INSERT/UPDATE/DELETE) because the index must also be maintained.
In Mongoose, how do you enforce that a field is required and unique?
In the schema definition set the field options { required: true, unique: true }. Note: 'unique' is not a validator but a directive to build a unique index on that field.
What is the aggregation pipeline in MongoDB?
A framework that processes documents through a sequence of stages (e.g., $match, $group, $sort, $project, $lookup), where each stage transforms the stream and passes results to the next — used for grouping, filtering, and computing aggregates.
What environment-variable practice is recommended for storing a database connection string in a Node.js app?
Store credentials/URIs in environment variables loaded from a .env file (e.g., via the dotenv package as process.env.DATABASE_URL), keep .env out of version control, and never hard-code secrets in source.
What is the difference between findOne() returning null and find() returning an empty array when no documents match (MongoDB/Mongoose)?
findOne() (and findById) resolves to null when no document matches. find() always resolves to an array — an empty array [] when nothing matches — so you check .length rather than for null.
In SQL, what is the difference between DELETE, TRUNCATE, and DROP?
DELETE removes selected rows (can use WHERE, is transactional, logs each row). TRUNCATE quickly removes all rows but keeps the table structure and resets identity counters. DROP removes the entire table (structure and data).
What this deck covers
The Database Integration deck follows the NodeJS Database Integration syllabus — 2 chapters and 6 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 25.0 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 195 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Database Integration flashcards FAQ
How many Database Integration flashcards are in this NodeJS deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these NodeJS flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Database Integration cards cover?
They follow the NodeJS Database Integration syllabus — 2 chapters and 6 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.