Skip to content

Server

The server is built on fastify.

Node version 20.18.3 is the highest version on hosting.com.

When setting up the server, on hosting create the application using setup node.js in control panel, that create the virtual directories and links for node_modules. After that the depoy script can handle it.

The hosting service uses “main” from package.json for starting.

This server takes a request, authenticates it, uses zod to validate I/O, drizzle handles the database, with type safety from drizzle-zod.

  • “name”: “server”,
  • “version”: “1.0.0”,
  • “main”: ”./dist/server.js”,
  • “keywords”: [],
  • “author”: "",
  • “license”: “ISC”,
  • “type”: “commonjs”,
  • “description”: "",
  • @fastify/compress:

  • @fastify/cookie:

    A plugin for Fastify that adds support for reading and setting cookies.

@fastify/cors:

  • @fastify/helmet:

  • @fastify/jwt:

  • @fastify/multipart:

  • @fastify/rate-limit:

  • @fastify/static:

  • argon2:

  • dotenv:

  • dotenv-cli:

    Gets the .env variables for running in scripts.

  • drizze-orm:

    Database ORM

  • fast-jwt:

    Fast JSON Web Token implementation.

  • fastify:

    Fast and low overhead web framework, for Node.js.

  • http-status-codes:

    Utility for accessing and converting status codes.

  • nodemailer:

    Nodemailer is the most popular email sending library for Node.js. It makes sending emails straightforward and secure, with zero runtime dependencies to manage.

  • pg-error-enum:

    Helper for postgress error typing.

  • pino:

    Very low overhead JavaScript logger.

  • pino-pretty:

  • xss:

  • zod;

    TypeScript-first schema validation with static type inference.

  • @types/jest:

  • @types/node:

  • @types/nodemailer:

  • @types/supertest:

  • concurrently:

  • copyfiles:

  • cross-env:

    Handles scripts for multiple environments, e.g. Linux, Windows etc.

  • jest:

  • supertest:

  • ts-jest:

  • ts-node:

  • typescript:

  • typescript-json-schema:

In traffic.ts from boilerplate for testing ?

  • axios:

    Promise based HTTP client for the browser and node.js

  • faker:

    Generate massive amounts of fake (but realistic) data for testing and development.

  • build: “tsc —project ./tsconfig.build.json”,
  • build:copy: “npm run prisma:copy && npm run copy:templates”,
  • clean: “rm -rf dist/*”,
  • copy:templates: “copyfiles -u 1 src/**/*.html dist”,
  • dev: “cross-env NODE_ENV=development concurrently -k “tsc —project ./tsconfig.build.json —watch” “nodemon —watch ’./dist’ —exec ‘node’ ./dist/server.js"",
  • prisma:copy: “copyfiles -u 1 src/generated/**/* dist”,
  • prisma:dev:gen: “prisma:migrate:dev && prisma:generate:dev”,
  • prisma:migrate:dev: “dotenv -e .env.development — npx prisma migrate dev”,
  • prisma:migrate:prod: “dotenv -e .env.production — npx prisma migrate deploy”,
  • prisma:generate:dev: “dotenv -e .env.development — npx prisma generate”,
  • prisma:generate:prod: “dotenv -e .env.production — npx prisma generate”,
  • “prisma:studio: “prisma studio”,
  • test: “jest —watchAll”,
  • start: “ts-node src/server.ts”

Specifies the environment mode the application runs in (e.g., development, production, test).

The domain and port where the application is hosted.

The port number the server listens on.

The base server URL without protocol or port.

The allowed origin for Cross-Origin Resource Sharing (CORS) requests.

Secret key used to sign and verify access tokens. Should be a cryptographically secure random string.

Time duration before access tokens expire (e.g., 20m for 20 minutes).

Secret key used to sign and verify refresh tokens. Should be a cryptographically secure random string.

Time duration before refresh tokens expire (e.g., 90d for 90 days).

Number of days until refresh tokens expire (alternative time format).

The name of the HTTP cookie used to store the refresh token.

The hostname or IP address of the database server.

The name of the database to connect to.

The password for authenticating with the database.

The port number the database server listens on.

The database protocol/driver to use (e.g., postgres, mysql).

The username for authenticating with the database.

The hostname of the SMTP server for sending emails.

The port number of the SMTP server.

The username for authenticating with the SMTP server.

The password for authenticating with the SMTP server.

The email address used as the sender for outgoing emails.

The default recipient email address (typically used for testing or notifications).

Time in milliseconds before email verification tokens expire.

Prefix used for application metrics collection and reporting.

The minimum level of logs to output (e.g., info, debug, error, warn).