Skip to content

Starting template for a NodeJS, Typescript web server using express and postgres

Notifications You must be signed in to change notification settings

kylemartin120/node-server-template

Repository files navigation

node-server-template

Designed as a ready-to-go template for developing a Node TypeScript server. It uses the following main dependencies:

  • express for the general web app framework
  • zod for schema validation
  • pg for the database (PostgreSQL)

When you fork this repo, replace all the instances of the name node-server-template with your repo/service name, and replace the example files in the routes, service, schemas, and model layers with your real-life code.

The currently-used port is 3000, which you can change in app.ts if desired.

Prerequisites

  • Install nvm, then run nvm i and nvm use to install Node.
  • Install the docker CLI (the easiest way is likely to install Docker Desktop).

Setup and running locally

When you first setup the server locally, you will need to run the following:

npm ci
npm run startDb
npm run migrate up

You can then run the server with npm start. This will compile the server and run it in watch mode, so it will automatically recompile and restart on any src changes.

Other commands

  • npm run migrate will run node-pg-migrate. See the docs here for details. Some common uses:
    • npm run migrate create <myMigrationName> will create a new migration.
    • npm run migrate up will run all migrations.
    • npm run migrate down will undo all migrations (essentially fully resetting the DB).
  • npm run compile will just compile without running the server.
  • npm run lintCheck will check for ESLint errors; npm run lintFix will fix them.
  • npm run formatCheck will check for prettier errors; npm run formatFix will fix them.
  • npm run stopDb or npm run restartDb will stop or restart the DB in Docker.

About

Starting template for a NodeJS, Typescript web server using express and postgres

Resources

Stars

Watchers

Forks