This a small example project using Nest.js, created for the Rentsody project. It consists in a basic live chat with chat history using a SQLite DB, Observables and websockets.
It has several features:
- Type-safe config
- All the gateways, services and controllers have complete Jest tests
- Using Prisma as a ORM and SQLite as a quick mockup DB
- Using observables and websockets
- Includes a Swagger URL (
/api
) and every route is fully described with examples, parameters, etc... - Production-ready logs: Using buffered logs, with Pino, it also logs crashes and HTTP/Socket requests
- Using Nest.js DTOs and validators
- Clone this repo
- Run
cp .env.example .env
, it has the port to use as a sample config - Run
pnpm install
(it should also work withnpm
but I usedpnpm
). This will also generate the types from Prisma, create a SQLite DB and seed it with some messages - Run
pnpm run start:dev
to launch the server in Dev mode. Ready!
Once it is running, you will see lots of logs but one tells you the URL were the API is listening to. By default it is listening at http://localhost:3000
.
If you type in your browser http://localhost:3000/api
, you will see the Swagger for the project.
If you type http://localhost:3000/ping
, you will see a basic pong endpoint.
If you type http://localhost:3000
, a static page will load with a live chat. Enter any username and you will see all the seeded messages and any other message you send in realtime. Feel free to try in different windows at the same time.
If you run pnpm run test
the tests will run and (hopefully) nothing will fail.
If you change the PORT
var in the .env
, you will also need to modify the port where the API is in the /client/index.html
file, so the static page knows where to connect to the API.