This application is a simple typescript API using the Prisma ORM, Neon and Express.js. It returns a list of authors and books written by them. This project uses Prisma to generate and run database migrations.
To build this project from scratch, check out the guide in Neon's documentation.
You will need the following:
- A Neon account and a project
- Node.js and npm
- Clone this repository.
git clone https://github.com/neondatabase/guide-neon-prisma
- Navigate to the project directory and install the dependencies.
cd guide-neon-prisma
npm install
- Create a
.env
file in the root of the project and add the following environment variables:
DATABASE_URL=
- Run the migrations using Prisma.
npx prisma migrate dev
- Add some entries to the database by running the seed script.
node seed.js
- Start the server.
node index.js
- Visit
http://localhost:3000
in your browser to see the list of authors and books. Or use curl to access the api from the terminal.
# Get a list of authors
curl http://localhost:3000/authors
# Get books by author with id 1
curl http://localhost:3000/books/1