This is a boilerplate repository for creating a new Docker project using Node, NestJS, React, Mongo, Material-UI along with quick start commands (check Makefile/ReadMe).
Best practices have been used and implemented to my knowledge to ensure the longevity of this project. For example a multi-database architecture is being used to distribute the load to the databases. Encourage pull requests for improving the workflow and processes + maintenance updates.
This project includes the bare minimum for authentication and authorization e.g: a user is able to create an account and sign-in (with password hashing, form validation on front-end).
Step debugging through VS Code is enabled and launch.json provided (see below).
The following dependancies have been added to improve developer workflow and build the application.
- Docker Docker is a containerization software.
- MongoDB MongoDB database.
- Nest.js Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications.
- React JS Core front-end technology
- Material UI Component library
Clone the repository, change all references to {PROJECT_NAME} in all files (do find and replace), also ensure project name matches the root directory name Eg: docker-compose.yml, Makefile, .env files (client/app) etc..
git clone https://github.com/jaybabak/docker-nestjs-mongodb-react-typescript-starter-kit
Update .env files for both client and app.
Change directory.
cd /app
Install Nest.js CLI globally
npm i -g @nestjs/cli
Run the following command to install the dependancies, make sure to be inside the "app" directory.
npm install
Run the following command to build the containers and start the development environment, make sure to be inside the "app" directory.
make up
Run the container and Nest.js development environment in quiet/silent mode (not recommended for local development, this hides the console output).
make up-silent
In a new terminal window, change directory to "client" folder.
cd /client
Run the following command to install the dependancies, make sure to be inside the "client" directory.
npm install
Run the following command to build the containers and start the development environment, make sure to be inside the "client" directory.
make up
Get connection string URL's, run the following command in /app directory.:
make db
Access MongoDB outside Docker containers:
mongodb://{PROJECT_NAME}:{PROJECT_NAME}@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.0
Access MongoDB within the Docker containers, use this URL for the app to connect to MongoDB instance:
mongodb://{PROJECT_NAME}:{PROJECT_NAME}@mongo:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.0
Visit back-end http://localhost:3002.
Visit front-end http://localhost:3000.
Update /etc/hosts (mac) if you want to use a custom development domain with the following:
localhost:3000 my-site.dev
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"address": "localhost",
"name": "Debug NestJS in Docker",
"port": 9229,
"remoteRoot": "/usr/src/app",
"sourceMaps": true,
"restart": true,
"localRoot": "${workspaceFolder}/app",
}
]
}
Command | Description |
---|---|
help | Prints the help screen. |
up | Builds the application container and starts it with logging. |
build | Rebuilds the application container and starts it with logging. |
up-silent | Builds the application container and starts it in background mode, no active logging. |
down | Stops and removes the docker containers. |
stop | Stops the running containers. |
shell | SSH into the main app container. |
shell-db | SSH into the MongoDB container with mongosh |
db | Get the MongoDB connection string |
To get a list of all available commands
make help