Introduction
The Memory App is a web application that enables users to create and share memories with others. The app is built using JavaScript language, MongoDB for the database, and follows the MVC (Model-View-Controller) architecture. In this blog post, we will discuss the project structure of the Memory App, and explain how to install and run the app via Docker.
Project Structure
The Memory App has a well-organized project structure that includes several important files and directories. The following is a brief description of each directory:
- The
app.js
file serves as the entry point for the application. - The
config
directory contains thedb.js
file, which sets up the database connection. - The
controllers
directory includes files that handle the logic for different routes, such ascommentController.js
andmemoryController.js
. - The
middleware
directory includes files that handle authentication and error handling, such asauthMiddleware.js
anderrorMiddleware.js
. - The
models
directory includes files that define the schema for different data types, such asmemoryModel.js
anduserModel.js
. - The
routes
directory includes files that define the various API endpoints for the app, such asmemoryRoutes.js
anduserRoutes.js
. - The
services
directory includes files that handle the business logic for different features, such asmemoryServices.js
anduserServices.js
. - The
utils
directory includes files that handle utility functions, such asuploadImage.js
andsendMail.js
. - The
validators
directory includes files that handle input validation, such asmemoryValidator.js
anduserValidator.js
.
Docker Installation
Docker is a containerization platform that enables developers to package their applications and dependencies together in a portable container. This allows for consistent and reproducible environments across different development, testing, and production environments. The Memory App can be easily installed and run using Docker.
Before installing the Memory App, make sure that Docker is installed on your system. You can download the Docker Desktop for Windows or Mac, or install the Docker Engine for Linux.
Once Docker is installed, navigate to the root directory of the Memory App in your terminal. The app is configured to be run using Docker Compose, which is a tool for defining and running multi-container Docker applications. The app's Docker Compose configuration is defined in the file docker-compose.yml
.
To start the app, run the command docker-compose up
in the terminal. This command will start the app's containers and make the app available at http://localhost:5000/api/memory
.
To stop the app and remove the containers, run the command docker-compose down
.
To run the app in production mode, use the command docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
. This will make the app available at http://localhost/api/memory
.
You can pass an additional flag -d
to the command to keep the containers running in the background.
It is also possible to override the default settings of the compose file using a separate override file by running the command docker-compose -f docker-compose.yml -f docker-compose.override.yml up
. docker-compose up
automatically applies this if we name the file docker-compose.override.yml
.
In production mode, the environment variables need to be set in the production environment. We could create a separate .env
file for production and provide it inside the docker-compose.prod
file. We could also containerize a MongoDB database.
idrsdev / memoryapp
API for a social media application where user can post, share, view, comment and like memories.
Table of Contents
Installation
Locally
Install Dependencies
$ npm install
$ cp .env.example .env
set these environment variables
Run
npm run dev (:5000)
Docker
$ docker compose up
Available at http://localhost:5000/api/memory
To stop and remove containers
$ docker compose down
To run in production mode
$ docker compose -f docker-compose.yml -f docker-compose.prod.yml up
Available at http://localhost/api/memory
You can pass an additional flag -d
to keep it running in background
API Docs
BaseURL : http://localhost:5000/api
Open Endpoints
Open endpoints require no Authentication.
Login POST /user/login/
Endpoints that require Authentication
Closed endpoints require a valid Token to be included in the header of the request. A Token can be acquired from the Login view above.
Memory related
Endpoints for viewing and manipulating the Memories.
-
Create Memory:
…
Top comments (0)