A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript starter repository.
This repository contains a NestJS backend for an Item Management System using MikroORM and PostgreSQL. This README provides step-by-step baby steps to get the project running locally on Windows PowerShell, how to run migrations and seeders, and troubleshooting tips.
- Project overview
- Prerequisites
- Quick start (PowerShell)
- Environment variables
- Scripts (npm)
- Migrations (MikroORM)
- Seeders
- Building for production
- Common troubleshooting
- Contributing
- License
Backend built with:
- NestJS (TypeScript)
- MikroORM (PostgreSQL)
- Swagger for API docs
The MikroORM configuration lives at src/mikro-orm.config.ts. Migrations and seeders are configured to run from dist/ in production, and from src/ during development when using TypeScript paths.
- Node.js (16+ recommended)
- npm (or yarn) — this README uses npm commands
- PostgreSQL database
- PowerShell (you're using Windows PowerShell by default)
- Clone repository
git clone <your-repo-url>
cd item-managment-system- Install dependencies
npm install- Create
.envfrom template and fill values
Create a file named .env in the project root with the following keys (example values):
# application
PORT=3000
# database
DB_NAME=xyric_db
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_PORT=5432
HOST=localhost- Start the app in development mode
npm run start:devOpen http://localhost:3000/v1/api (or replace 3000 with your PORT) to reach the API. Swagger UI is available at /api (e.g. http://localhost:3000/api).
PORT- port used by the server (default in.envexample is 3000)DB_NAME- Postgres database nameDB_USERNAME- Postgres userDB_PASSWORD- Postgres passwordDB_PORT- Postgres port (usually 5432)HOST- Postgres host
Keep secrets out of source control. Use a .env.local or environment secrets in CI/CD.
Key scripts in package.json:
npm run start— start production server (expectsdist/compiled files)npm run start:dev— run NestJS in watch mode (development)npm run build— compile TypeScriptnpm run lint/npm run lint:fix— lintingnpm run migration:create— create a migration filenpm run migration:up— apply pending migrationsnpm run migration:down— revert last migrationnpm run migration:list— list migrationsnpm run seed:run— run seedersnpm run seed:create— create a seeder
Note: when passing arguments to npm scripts, use -- to forward arguments. Example:
# create migration named CreateItemsTable
npm run migration:create -- -n CreateItemsTable
# create a seeder named MySeeder
npm run seed:create -- -n MySeederThis project uses MikroORM migrations. Two common flows:
Option A — Build then run migrations (recommended for production):
npm run build
npm run migration:upOption B — Run migrations directly in development with ts-node (if you have ts-node registered in your CLI settings):
# forward args to the CLI
npm run migration:create -- -n AddNewColumnToItems
npm run migration:upImportant notes:
- The
mikro-ormCLI readsmikro-orm.config.tsfromsrc/(this project kept its config atsrc/mikro-orm.config.ts). If the CLI cannot find the config, ensure your current working directory is the project root. - Generated migration files will appear under
src/database/migrations(TypeScript) anddist/database/migrations(compiled JS).
Seeders are found in src/database/seeders and configured in src/mikro-orm.config.ts.
Create a new seeder:
npm run seed:create -- -n ItemSeederRun seeders:
npm run build
npm run seed:runIf you prefer running seeders during development without building, ensure your seeder class and the mikro-orm CLI are able to load TypeScript seeder files.
- Build the app
npm run build- Run migrations (on the compiled
dist/code)
npm run migration:up- Start the server
npm run start:prod-
Error: Missing
PORTor DB environment variables- Ensure
.envexists and values are set. Restart terminal if you changed system env variables.
- Ensure
-
MikroORM cannot find config or entities
- Make sure
src/mikro-orm.config.tsexists and paths inentities/entitiesTsmatch your project structure. - When running migration commands without building, confirm the CLI can load TypeScript config (sometimes you need
ts-node/register). Building then running migrations is the simplest option.
- Make sure
-
TypeScript compile errors when starting
- Run
npm run buildto view compile-time errors. Fix types or missing imports the compiler highlights.
- Run
-
Port already in use
- Either choose a different
PORTin.envor stop the process using that port.
- Either choose a different
-
nestcommand not found / script fails- Ensure devDependencies are installed. If using global Nest CLI,
npm i -g @nestjs/cli(optional).
- Ensure devDependencies are installed. If using global Nest CLI,
If you still see an error when running npm run start:dev, copy the terminal stack trace and open an issue or paste it here for help — include the first 20 lines of the error and the file/line the stack points to.
- Make a fork and open a pull request
- Keep commits small and focused
- Run
npm run lintandnpm run testbefore submitting
This repository uses the license in package.json (UNLICENSED). Change this file if you intend to open-source the project.
If you'd like, I can also:
- add a
.env.examplefile to the repo with the variables shown above - add a tiny
Makefile/PowerShell script to simplify build/migrate/seed steps - run the project in the terminal to capture the original startup error you reported
Tell me which of the extras you'd like me to do next.