- 1. Prerequisites
- 2. Installation
- 3. Running the Application
- 4. Environment Configuration
- 5. Prerequisites to run the Application in Docker
- 6. Build the Docker image using the provided Dockerfile
- 7. Run the Application
- 8. Accessing the Application
- 9. Stopping and Cleaning Up
- 10. Generating Migration
- 11. Run Migration
- 12. Revert Migration
Before running the application, make sure you have the following dependencies installed:
- Node.js: Download and Install Node.js
- npm (Node Package Manager): It comes with Node.js, so no need to install separately.
Clone the repository and install project dependencies.
git clone https://github.com/katelovestocode/backend-internship.git
cd your-project-directory
npm install
Start your Nest.js application on port 3002 using the following command:
npm run start:dev
To configure your Nest.js application, you will need an environment (.env
) file. This file is used to store sensitive data and configuration settings. Here's how you can set up your .env
file:
-
Create an
.env
file in the root of your project directory. -
Define your environment variables in the
.env
file. You need to specify values for variables like PORT, database connection URLs, API keys, and other configuration settings. For example:PORT=3002
Before you can run the application in Docker, make sure you have the following dependencies installed on your machine:
- Docker: Download and install Docker from https://www.docker.com/get-started.
docker build -t docker-image-test --progress=plain --no-cache --target test .
docker build -t docker-image-prod --progress=plain --no-cache --target prod .
Now that you have built the Docker image, you can run the application within a Docker container. Use the following command:
docker run -d -p 3002:3002 --name docker-container-test docker-image-test
docker run -d -p 3002:3002 --name docker-container-prod docker-image-prod
Once the container is up and running, you can access the application in your web browser by navigating to:
http://localhost:3002
To stop the Docker container, use the following command:
docker stop docker-container-prod
docker stop docker-container-test
To remove the Docker container and image when you're done, run:
docker rm docker-container-prod
docker rmi docker-container-prod
docker rm docker-container-test
docker rmi docker-container-test
To create a new database migration, use the following command:
npm run migration:generate -- db/migrations/<migration-name>
Replace with a descriptive name for your migration. This will generate the necessary files for applying changes to the database schema.
Once you've generated a migration, you can apply the changes to your database by running the migration:
npm run migration:run
If you need to revert a migration (roll back changes to the previous state), you can use the following command:
npm run migration:revert
This will undo the most recent migration and revert your database schema to the previous state.