Initialize Prisma in a TypeScript Node Project

Ryan Chenkie
InstructorRyan Chenkie
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

The Prisma CLI comes with commands to initialize Prisma in a project, run migrations, generate Prisma Client and more. In this lesson, we install the relevant dependencies and initialize Prisma in a TypeScript Node project.

Ryan Chenkie: [0:00] Here's a simple web server using Express and TypeScript. We've got server.ts. We are bringing in Express, and then we've got a single endpoint here at /ping, which sends back a message in this object here.

[0:13] If we want to start sending back some dynamic data using Prisma, we first need to get Prisma installed. In the command line, do npm install as a dev-dependency prisma. This will give us the Prisma CLI, and it will give us access to all the commands that we need to get Prisma initialized and do other tasks as well.

[0:32] Next, let's install as a regular dependency @prisma/client. This will give us access to Prisma Client, which is what we use to access our database.

[0:42] With those in place, we can now do npx prisma init. This will initialize Prisma in this project. What that does is it gives us access to this directory here called prisma. Within the prisma directory, we have schema.prisma. This is the file where we describe our database, the relationships between tables, and other information so that we can have Prisma derive a type-safe database access client for us.

[1:09] Prisma supports several relational databases, including Postgres, MySQL, SQLite and SQL Server. For now, let's use SQLite. That will give us a very easy way to use a database on the file system. Instead of pointing to the database URL in the environment file that we've got, let's change this up to go directly to file. Then we'll put the colon dot, and it'll be dev.db.

[1:34] This file doesn't yet exist, but it will be created for us automatically once we run a command to get our initial migration in place.

egghead
egghead
~ 18 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today