How To Start Up The Application
Fork and clone the repository
git clone https://github.com/hngprojects/hng_boilerplate_nestjs.git
cd hng_boilerplate_nestjs
git checkout chore/database-setup
Setting Up the Environment
Ensure you have NodeJs and Npm installed.
You can download and install Node.js from nodejs.org .
Check your installation here:
Ensure you have NestJs installed
Install the NestJS CLI globally using npm:
npm install -g @nestjs/cli
Ensure PostgreSQL is installed and running.
Update the .env file with your database credentials
PROFILE=local
NODE_ENV=development
PORT=3008
DB_TYPE=dt_type
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_HOST=localhost
DB_DATABASE=db_name
DB_ENTITIES=dist/**/*.entity{.ts,.js}
DB_MIGRATIONS=dist/db/migrations/*{.ts,.js}
Running The Application Locally
Start the application in dev mode
Create And Apply Migration Files
Migration files should be placed in the db/migration
directory.
Generate migration files automatically with typeorm
npm run migration:generate
To manually create migration file
The seed data is run once when app starts
You can test the endpoint using curl or Postman
curl -X GET http://localhost:3008/api/v1/users/
Using Postman
Expected Response
{
"id" : " d6aa5dc9-a1c3-4516-ad4e-31d169893510" ,
"first_name" : " John" ,
"last_name" : " Smith" ,
"email" : " [email protected] " ,
"password" : " $2b$10$lOsaGJVjYxxZsVQ2WNsiwe./MEu.MEp2QiXKAS1FwP3gQtctOM2tG" ,
"is_active" : null ,
"attempts_left" : null ,
"time_left" : null ,
"created_at" : " 2024-07-20T13:08:28.273Z" ,
"updated_at" : " 2024-07-20T13:08:28.523Z" ,
"profile" : {
"id" : " 6f8984f8-682a-4bb9-a618-6b14ea109bd3" ,
"username" : " johnsmith" ,
"bio" : " bio data" ,
"phone" : " 1234567890" ,
"avatar_image" : " image.png"
},
"products" : [
{
"id" : " 61c30739-1b7e-447a-b58e-3b05e0e7c0d3" ,
"product_name" : " Product 1" ,
"product_price" : 100 ,
"description" : " Description 1"
}
],
"organisations" : [
{
"org_id" : " c52d7c25-8632-4b08-91d1-1f9a837f1861" ,
"org_name" : " Org 1" ,
"description" : " Description 1"
},
{
"org_id" : " 4b42ea8e-e1e2-407e-88cb-9893c05a4167" ,
"org_name" : " Org 2" ,
"description" : " Description 2"
}
]
}
There are 2 default users created when you start the application.
To get the sample data, use this route after starting the application:
http://localhost:3008/api/v1/seed/users
Also, you can get the users by signing in to your database and query the users table using:
SELECT * FROM users;
# Quick Start Guide
How To Start Up The Application
Fork and clone the repository
git clone https://github.com/hngprojects/hng_boilerplate_nestjs.git
cd hng_boilerplate_nestjs
git checkout chore/database-setup
Setting Up the Environment
Ensure you have NodeJs and Npm installed.
You can download and install Node.js from nodejs.org .
Check your installation here:
Ensure you have NestJs installed
Install the NestJS CLI globally using npm:
npm install -g @nestjs/cli
Ensure PostgreSQL is installed and running.
Update the .env file with your database credentials
PROFILE=local
NODE_ENV=development
PORT=3008
DB_TYPE=dt_type
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_HOST=localhost
DB_DATABASE=db_name
DB_ENTITIES=dist/**/*.entity{.ts,.js}
DB_MIGRATIONS=dist/db/migrations/*{.ts,.js}
Running The Application Locally
Start the application in dev mode
Create And Apply Migration Files
Migration files should be placed in the db/migration
directory.
Generate migration files automatically with typeorm
npm run migration:generate
To manually create migration file
The seed data is run once when app starts
You can test the endpoint using curl or Postman
curl -X GET http://localhost:3008/api/v1/users/
Using Postman
Expected Response
{
"id" : " d6aa5dc9-a1c3-4516-ad4e-31d169893510" ,
"first_name" : " John" ,
"last_name" : " Smith" ,
"email" : " [email protected] " ,
"password" : " $2b$10$lOsaGJVjYxxZsVQ2WNsiwe./MEu.MEp2QiXKAS1FwP3gQtctOM2tG" ,
"is_active" : null ,
"attempts_left" : null ,
"time_left" : null ,
"created_at" : " 2024-07-20T13:08:28.273Z" ,
"updated_at" : " 2024-07-20T13:08:28.523Z" ,
"profile" : {
"id" : " 6f8984f8-682a-4bb9-a618-6b14ea109bd3" ,
"username" : " johnsmith" ,
"bio" : " bio data" ,
"phone" : " 1234567890" ,
"avatar_image" : " image.png"
},
"products" : [
{
"id" : " 61c30739-1b7e-447a-b58e-3b05e0e7c0d3" ,
"product_name" : " Product 1" ,
"product_price" : 100 ,
"description" : " Description 1"
}
],
"organisations" : [
{
"org_id" : " c52d7c25-8632-4b08-91d1-1f9a837f1861" ,
"org_name" : " Org 1" ,
"description" : " Description 1"
},
{
"org_id" : " 4b42ea8e-e1e2-407e-88cb-9893c05a4167" ,
"org_name" : " Org 2" ,
"description" : " Description 2"
}
]
}
There are 2 default users created when you start the application.
To get the sample data, use this route after starting the application:
http://localhost:3008/api/v1/seed/users
Also, you can get the users by signing in to your database and query the users table using:
SELECT * FROM users;