Data for Expresss
Database integration in Express connects route handlers to persistent storage, using a driver such as pg or mongodb, a query builder, or an ORM such as Prisma or Sequelize. Good practice is a connection pool created once at start-up and a separate data-access layer so handlers stay thin.
Stage: Building APIs · Part of the Express roadmap · Last reviewed 19 November 2026
What to learn in Data
- Connect to PostgreSQL or MongoDB once at start-up and reuse a connection pool
- Implement create, read, update and delete endpoints backed by a database
- Use parameterised queries so user input never becomes executable SQL
- Keep database code in a service or repository module rather than in route handlers
- Store connection strings and credentials in environment variables
Data interview questions
Why use a connection pool instead of opening a connection per request?
Opening a database connection is slow and databases limit how many can be open. A pool keeps a set of connections ready and shares them across requests, which lowers latency and prevents overloading the database.
How do you stop SQL injection in an Express app?
Never build SQL by concatenating request values. Use parameterised queries or an ORM that binds parameters, so the database treats input purely as data. Validating input and using a least-privilege database account add further protection.
Where Data fits in the Express roadmap
Data belongs to the Building APIs stage (beginner level). Real endpoints.
Other units in this stage
Back to the full Express roadmap