- Notifications
You must be signed in to change notification settings - Fork694
Exemplary real world backend API built with NestJS + TypeORM / Prisma
lujakob/nestjs-realworld-example-app
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
NestJS codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to theRealWorld API spec.
Clone the repository
git clone https://github.com/lujakob/nestjs-realworld-example-app.gitSwitch to the repo folder
cd nestjs-realworld-example-appInstall dependencies
npm installCopy config file and set JsonWebToken secret key
cp src/config.ts.example src/config.tsThe codebase contains examples of two different database abstractions, namelyTypeORM andPrisma.
The branchmaster implements TypeORM with a mySQL database.
The branchprisma implements Prisma with a mySQL database.
Create a new mysql database with the namenestjsrealworld
(or the name you specified in the ormconfig.json)
Copy TypeORM config example file for database settings
cp ormconfig.json.exampleSet mysql database settings in ormconfig.json
{ "type": "mysql", "host": "localhost", "port": 3306, "username": "your-mysql-username", "password": "your-mysql-password", "database": "nestjsrealworld", "entities": ["src/**/**.entity{.ts,.js}"], "synchronize": true}Start local mysql server and create new database 'nestjsrealworld'
On application start, tables for all entities will be created.
To run the example with Prisma checkout branchprisma, remove the node_modules and runnpm install
Create a new mysql database with the namenestjsrealworld-prisma (or the name you specified inprisma/.env)
Copy prisma config example file for database settings
cp prisma/.env.example prisma/.envSet mysql database settings in prisma/.env
DATABASE_URL="mysql://USER:PASSWORD@HOST:PORT/DATABASE"To create all tables in the new database make the database migration from the prisma schema defined in prisma/schema.prisma
npx prisma migrate save --experimentalnpx prisma migrate up --experimentalNow generate the prisma client from the migrated database with the following command
npx prisma generateThe database tables are now set up and the prisma client is generated. For more information see the docs:
npm start- Start applicationnpm run start:watch- Start application in watch modenpm run test- run Jest test runnernpm run start:prod- Build application
This application adheres to the api specifications set by theThinkster team. This helps mix and match any backend with any other frontend without conflicts.
More information regarding the project can be found herehttps://github.com/gothinkster/realworld
npm start- Test api with
http://localhost:3000/api/articlesin your favourite browser
This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using theAuthorization header withToken scheme. The JWT authentication middleware handles the validation and authentication of the token. Please check the following sources to learn more about JWT.
This example repo uses the NestJS swagger module for API documentation.NestJS Swagger -www.swagger.io
About
Exemplary real world backend API built with NestJS + TypeORM / Prisma
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
