GithubHelp home page GithubHelp logo

prisma / blog-backend-rest-api-nestjs-prisma Goto Github PK

View Code? Open in Web Editor NEW
145.0 4.0 36.0 216 KB

A simple backend REST API for a blog built using NestJS, Prisma, PostgreSQL and Swagger.

Home Page: https://www.prisma.io/blog/nestjs-prisma-rest-api-7D056s1BmOL0

JavaScript 6.44% TypeScript 93.56%
nestjs postgres postgresql prisma rest-api swagger typescript

blog-backend-rest-api-nestjs-prisma's Introduction

Blog-Backend-REST-API-NestJS-Prisma

A simple backend REST API for a blog built using NestJS, Prisma, PostgreSQL and Swagger.

Installation

  1. Install dependencies: npm install
  2. Start a PostgreSQL database with docker using: docker-compose up -d.
    • If you have a local instance of PostgreSQL running, you can skip this step. In this case, you will need to change the DATABASE_URL inside the .env file with a valid PostgreSQL connection string for your database.
  3. Apply database migrations: npx prisma migrate dev
  4. Start the project: npm run start:dev
  5. Access the project at http://localhost:3000/api

blog-backend-rest-api-nestjs-prisma's People

Contributors

ruheni avatar tasinishmam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

blog-backend-rest-api-nestjs-prisma's Issues

While Npm run build error are there like

1____src/Common/prisma-client-exception/prisma-client-exception.filter.ts:8:15 - error TS2339: Property 'PrismaClientKnownRequestError' does not exist on type 'typeof Prisma'.

2___ error TS2305: Module '"@prisma/client"' has no exported member 'Role

thanks for nice tutorial applied it loved it but how to solve above thing

Empty validation for articles

Hi @TasinIshmam!

I was following another tutorial on the blog and found yours, which is the newest one, and decided to follow along.

I want to raise a point and see what you think about it. The CreateArticleDto has the IsOptional() decorator in the description property, which means it validates if the field is present or not. Then you have the IsString() decorator to validate if the property is a string. But at any moment you're validating if the string is "valid" or not.

Generally, I (personally) like to also add an IsNotEmpty() decorator, to ignore "" (empty strings) values as well. This way you enforce that description is optional, but if present, it cannot be empty.

Not a really big problem, but it can avoid, in a big db table, for example, the need to write SELECT * FROM ARTICLES WHERE description IS NOT NULL AND description <> ''.

Any thoughts? ๐Ÿ˜„

error: prisma migrate in windows

Bug description

Thx for your work, I learn a lot about how to using prisma in nest. But when i try to run npx prisma migrate dev --name "init" in windows, one error appears:
error info

I tried to google it, but not find methods to reolve it. Can you give me some suggestions? Thx again.

How to reproduce

git clone repo, and then

npm install
docker compose up

in another terminal

npx prisma migrate dev --name "init"

Environment

  • OS: windows 11

Wrong with image example

The images show "Request to /example with invalid arguments" and the server response with 200 status, the label on the image it's wrong

image

Can we get a second version with a more complex model?

Your article was awesome!!

But can you show proper way of using connections, and connect on create, create many on create, etc. I'm having tons of trouble figuring out how to use these functions and creating DTO's for these use cases.

Module not found when running `node dist/main`

Hi!

Im trying to deploy my Nest project on Heroku. So I duplicate your code to try and I get the same error.

Right just after clone the project, when I try to deploy by running npm run start:prod after a successful build I get the following error:

node:internal/modules/cjs/loader:1078
throw err;
^

Error: Cannot find module '/..../blog-backend-rest-api-nestjs-prisma-main/dist/main'
at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at Module._load (node:internal/modules/cjs/loader:920:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Node.js v18.15.0

Im new with Nestjs so I probably missing something?

Thanks for your help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.