2.6 KiB
title | description | slug | authors | tags | image | hide_table_of_contents | |||
---|---|---|---|---|---|---|---|---|---|
OpenPanel BETA is out! | Public beta is released! | openpanel-public-beta-released | stefanpejcic |
|
https://refine.ams3.cdn.digitaloceanspaces.com/website/static/img/placeholder.png | false |
:::caution
Something :::
Link to blog..
All the steps described are in this repo.
Intro
NestJS is a framework for building efficient, scalable Node.js server-side applications. With nestjsx/crud we can add CRUD functions quickly and effortlessly on this framework.
NestJS Rest Api
To start playing with NestJS you should have node (>= 10.13.0, except for v13) and npm installed.
Create Project Folder
mkdir job-posting-app
cd job-posting-app
Setting up a new project is quite simple with the Nest CLI. With npm installed, you can create a new Nest project with the following commands in your OS terminal:
npm i -g @nestjs/cli
nest new api
TypeORM is definitely the most mature ORM available in the node.js world. Since it's written in TypeScript, it works pretty well with the Nest framework. I chose mysql as database. TypeORM supports many databases (MySQL, MariaDB, Postgres etc.)
To start with this library we have to install all required dependencies:
npm install --save @nestjs/typeorm @nestjs/config typeorm mysql2
- Create an .env.example file. Here we will save the database information.
- Create and configured a docker-compose file for MySQL.
- Create a ormconfig.ts file for migrations.
- Add the following scripts to the
package.json
file for migrations.
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"db:migration:generate": "npm run typeorm -- migration:generate",
"db:migration:run": "npm run typeorm -- migration:run",
"db:migration:revert": "npm run typeorm -- migration:revert",
"db:refresh": "npm run typeorm schema:drop && npm run db:migration:run"