A basic task manager web REST API providing CRUD services on task and user data stored in MongoDB. The API is built with Express.js and runs on Node.js. The task and user data is managed with MongoDB and Mongoose.
The app is deployed on Heroku, and the database is hosted in the cloud with AWS using MongoDB Atlas. Check out the API Documentation for the features of MultiTask.
- Download MongoDB Community Server. Select the current MongoDB version, your host operating system, and
.tgz
package. - Extract the files from the downloaded archieve to your user home directory and rename the MongoDB folder
mongodb
. - Create a new folder called
mongodb-data
in the same directory to store the data. - Find your PATH name to the mongodb location, which is your user home directory:
$ cd ~; pwd
- Start up MongoDB
$ <PATH>/mongodb/bin/mongod --dbpath=<PATH>/mongodb-data
- Download MongoDB Compass Community Edition.
- Create a new connection with
Hostname: localhost
Port: 27017
- Install mongosh.
- Connect to a MongoDB deployment running on localhost with default port 27017 with:
$ mongosh
- Common commands for testing this project:
- List all databases:
$ show dbs
- Switch the database:
$ use <database>
- Show all collections in the current database:
$ show collections
- Retrieve all documents in the specified collection:
$ db.<collection>.find()
- Delete all documents in the specified collection:
$ db.<collection>.deleteMany({})
- Delete one document in the collection with the specified condition:
db.<collection>.deleteOne( { name: "Brad Pitt" } )
- List all databases:
- Install node modules
$ npm install
- Install
nodemon
globally
$ npm install nodemon -g
- Sign up and get EmailAPI key from SendGrid
- Create a new folder
/config
in the root folder and add a new file nameddev.env
into the folder. This folder is going to store the environment variables. - Paste below code to
dev.env
, changing the values of SendGrid API key, the jwt secret key, and email. The jwt key can be set to any random string. The email will be used as the sender of the welcome and cancellation emails.
PORT=3000
SENDGRID_API_KEY=<Your email API key from step #2>
JWT_SECRET=<Your JWT secret key>
MONGODB_URL=mongodb://127.0.0.1:27017/task-manager-api
EMAIL=<Your verified SendGrid sender email address>
- Run the app. Make sure MongoDB is up and running as well.
$ npm run dev
- Create a new file
test.env
in the/config
folder. The content would be the same as the content indev.env
but with a different variableMONGODB_URL
to create a separate test database and an additional variableUSER_EMAIL
to test email sending with SendGrid.
PORT=3000
SENDGRID_API_KEY=<Your email API key from step #2>
JWT_SECRET=<Your JWT secret key>
MONGODB_URL=mongodb://127.0.0.1:27017/task-manager-api-test
EMAIL=<Your verified SendGrid sender email address>
USER_EMAIL=<Another email address for receieving welcome/goodbye emails>
- Run tests in the
/tests
folder
$ npm test
If you are using VSCode, you can install the REST Client extension to do manual testing. The manual.http
file in the test folder contains some tests for the API.
Read the REST Client user guide for more information on test configurations.
The files .dockerignore
, Dockerfile
, and compose.yaml
are used to create Docker containers for this app. You will need to install Docker in your computer system.
-
Change
MONGODB_URL
indev.env
andtest.env
tomongodb://mngo:27017/task-manager-api
andmongodb://mongo:27017/task-manager-api-test
. -
Run
$ docker compose up -d
in the/Multitask
project directory to run the web and mongo services in detached mode. -
You can then run the Jest tests inside the Docker container by:
$ docker ps
to see the list of current running Docker containers.
$ docker exec -it <CONTAINER ID OF multitask-api-web> bash
to run commands in the multitask-api-web container.
$ npm test
to execute the Jest test suites inside the multitask-api-web container.
-
Stop the running services with
$ docker compose down
. -
If code has been changed, run
$ docker compose build --no-cache
to rebuild the Docker image. Use$ docker rmi <docker image id>
to remove unwanted Docker images.