- Language: TypeScript
- Dev watcher: tsx watch
- Architecture: MVC
- Database: Postgres (psql)
.
├── src
│ ├── app.ts
│ ├── server.ts
│ ├── routes
│ │ ├── health.ts
│ │ └── users.ts
│ ├── controllers
│ │ └── usersController.ts
│ ├── services
│ │ └── usersService.ts
│ ├── repositories
│ │ └── usersRepository.ts
│ ├── db
│ │ └── pool.ts
│ ├── errors
│ │ └── AppError.ts
│ ├── utils
│ │ └── getPort.ts
│ └── middleware
│ ├── errorHandler.ts
│ └── notFound.ts
├── __tests__
│ └── app.test.ts
├── db
│ ├── schema.sql
│ └── seed.sql
├── scripts
│ ├── dbCreate.js
│ ├── dbSetup.js
│ ├── dbSeed.js
│ └── dbReset.js
├── .env.example
├── .gitignore
├── .eslintrc.cjs
├── package.json
├── tsconfig.json
├── tsconfig.eslint.json
└── jest.config.js
This project uses a local PostgreSQL database. Follow the steps for your OS below.
macOS (using Homebrew):
brew install postgresql@17
brew services start postgresql@17Ubuntu / Debian:
sudo apt update && sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql && sudo systemctl enable postgresqlWindows: Download the installer from https://www.postgresql.org/download/windows/ and follow the prompts. Remember the password you set — you'll need it in step 2.
Your .env file connects as alex with password postgres. You need a matching PostgreSQL role.
Linux (run once):
sudo -u postgres createuser --createdb "$USER"
sudo -u postgres psql -c "ALTER USER \"$USER\" WITH PASSWORD 'postgres';"macOS: Homebrew already created a role for you. Run the commands above only if you get an auth error.
Windows: The installer created a postgres role. Edit DATABASE_URL in your .env to use it:
DATABASE_URL=postgres://postgres:YOUR_INSTALL_PASSWORD@localhost:5432/jobnative_digital_api_dev
pg_isreadyYou should see accepting connections.
npm install
cp .env.example .env
npm run db:create
npm run db:setup
npm run db:seed
npm run devRun npm run lint to check the code with ESLint.
- Add a router in
src/routes. - Call controller functions from that route.
- Put business rules in
src/services. - Put data access code in
src/repositories. - Register the route in
src/app.ts.
Use src/services for business logic. Controllers translate HTTP requests/responses, and repositories handle persistence.
src/middleware/notFound.tshandles unknown routes with a 404 JSON response.src/middleware/errorHandler.tsreturns{ status, message }and includesstackonly in development.
| Command | What it does |
|---|---|
npm run db:create |
Creates the database (safe to re-run) |
npm run db:setup |
Applies the schema (creates tables) |
npm run db:seed |
Inserts sample data |
npm run db:reset |
Drops and re-creates tables + sample data |
"connection refused" — PostgreSQL isn't running.
# Linux
sudo systemctl start postgresql
# macOS
brew services start postgresql@17"role does not exist" — Create a Postgres role for your OS user:
sudo -u postgres createuser --createdb "$USER"
sudo -u postgres psql -c "ALTER USER \"$USER\" WITH PASSWORD 'postgres';""password authentication failed" / "client password must be a string" — The credentials in DATABASE_URL are wrong or missing. Run the role setup commands in Prerequisites and make sure DATABASE_URL in .env matches.
"database does not exist" — Run npm run db:create.