peterrhodesdev / ntnp-stack

NTNP stack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NTNP stack

Next.js, Tailwind CSS, Nest.js, and PostgreSQL.

Setup

  • server/.env.example:
    • copy to server/.env.development
    • delete either the DB connection options variable group (DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME) or the DB connection string variable (DB_URL)
    • fill in the connection option for DB_PASSWORD or replace $DB_PASSWORD in the connection string
  • client/src/pages/_app.tsx: edit TITLE to set the default page title and the left text in the header

Commands

# Start the client (on port 3000):
cd client
npm run dev
# Start the server (on port 5000):
cd server
npm run start:dev
# Restore the database:
cd db
./run.sh restore
# Generate models for TypeORM from database:
cd db
./run.sh generate-models

API endpoints

# Get all
curl -X GET http://localhost:5000/examples
# Get one by id
curl -X GET http://localhost:5000/examples/{id}
# Delete
curl -X DELETE http://localhost:5000/examples/{id}
# Create
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"booleanField":true,"floatField":1.2,"integerConstrainedField":345,"numericField":6.7,"textNullableField":null,"timestamptzField":"2022-11-26T07:12:03.103Z","varcharConstrainedField":"abc"}' \
  http://localhost:5000/examples
# Update (full)
curl -X PUT \
  -H "Content-Type: application/json" \
  -d '{"booleanField":false,"floatField":-1.2,"integerConstrainedField":999,"numericField":-3.4E+2,"textNullableField":"\"\\\/","timestamptzField":"2022-11-26T07:12:03.103Z","varcharConstrainedField":"abcdef"}' \
  http://localhost:5000/examples/{id}
# Update (partial)
curl -X PATCH \
  -H "Content-Type: application/json" \
  -d '{"booleanField":false}' \
  http://localhost:5000/examples/{id}

Client setup

npx create-next-app client --ts --eslint
npm i -D eslint-config-prettier eslint-plugin-prettier
  • .eslintrc.json: edit extends, plugins, and rules
  • .prettierrc: create
npm i -D jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom
npm i -D tailwindcss postcss autoprefixer @tailwindcss/typography
npx tailwindcss init -p
npm i class-transformer reflect-metadata
  • src/pages/_app.tsx: import reflect-metadata
  • tsconfig.json: set experimentalDecorators to true
npm i react-query

Other

npm i validator
npm i -D @types/validator

Server setup

nest new server --strict
  • delete .git, README.md, src/app.controller.ts, src/app.controller.spec.ts, src/app.service.ts
  • .eslintrc.js: add prettier to rules
  • [optional] change test files to use .test instead of .spec
    • package.json: edit testRegex
    • tsconfig.build.json: edit exclude
npm i @nestjs/platform-fastify
npm i @nestjs/typeorm typeorm typeorm-naming-strategies pg

Configuration

npm i @nestjs/config
npm i -D cross-env
  • create a .env file
  • [optional] cross-env
    • so setting environment variables in scripts runs across platforms
    • package.json: set NODE_ENV to development for the start:dev script

Validation

npm i class-transformer class-validator @nestjs/mapped-types

Other

npm i -D @golevelup/ts-jest

About

NTNP stack

License:MIT License


Languages

Language:TypeScript 96.7%Language:JavaScript 2.1%Language:Shell 1.1%Language:CSS 0.1%