Archived on 2023/11/26.
This reposistory contains the source code that makes up the backend for AngularJSTodoApp, IonicTodoApp, and ElectronTodoApp.
Users are able to use this App as a Todo-List or a Note Taking application.
- User Login, Logout, Registration, Reset Password
- Add, Edit, Update, Delete, and Archive Notes/Tasks
- Supports sending out emails with Mailgun.
The best way to build, test, and run Nota is to use Docker. There are Dockerfiles in this repository that will automatically install MongoDB for local testing / development and Nota's dependencies.
-
The instructions below assume you have Docker and Docker Compose installed.
-
Clone this repo.
-
In the root of the project folder, run
docker-compose build
to build a local image of Nota.
Starting Interactive Mode
Running the following command will drop you into a bash shell where you can run various commands. The command will start MongoDB for you and make a volume mount from your host machine to the Docker container so that any file changes on the host will reflect in the container and vice versa.
docker-compose run --user="$(id -u)" --service-ports -v $(pwd):/home/backenduser/app nota bash
Exiting from Interactive Mode
Run exit
while in interactive mode will bring you back to your host's shell.
By running docker ps
, you will see that your containers are still running.
Run docker-compose down
to stop all running containers.
To run the tests for Nota, run the following command:
sudo docker-compose up --exit-code-from nota
The above command will start Nota and MongoDB and begin running the tests. The command will then shutdown the containers that were spun up for testing.
You will need to start the containers in interactive mode.
- Run
./scripts/test.sh
in the container to run the unit tests for Nota.
- After running the tests, you will see a coverage summary of the tests informing you what tests passed or not. Example in image below.
- You may also open
coverage/nota/index.html
file to see a break down of coverage for every file in a report. Example in image below.
-
Running the unit tests and having everything passing is an excellent indicator that your setup has all the dependencies installed.
-
You may click on the coverage badge above in this README to see the difference in coverage with changes that have made in already pushed branches.
-
Running the test script will create the database and drop it once tests are complete.
-
The 422 Bad response error is not related to Nota. It's an error that occurs when the tests are not ran on Travis-CI.
You will need to start the containers in interactive mode.
-
Run
./scripts/development.sh
to start the server in development mode. -
Running the server in development mode is useful for testing Nota manually.
-
If not already existing, this will create a development database for Nota.
-
You will see output to the console in this mode.
-
Kill the server by using CTRL-C.
-
If you want a clean run of the server again, be sure to drop the development database manually.
-
In the
Postman
directory, you may use the files in there to import a working collection and environment to test out the APIs of Nota. Postman is a great API testing software for testing out this backend. -
Robomongo / Robo 3T is an awesome way to manage your MongoDB databases.
Note: If you would like to connect to MongoDB from your host, you should be
able to with localhost:27017
while docker-compose is running the containers
in interactive mode. The same with Nota on localhost:3000
.
The way Nota is currently configured, it is assumed that you have a separate MongoDB
instance running somewhere where Nota can access it. There is no Docker image /
configuration provided for running MongoDB in production with Docker. Please
view the Dockerfile-mongodb
file
to see how you may use the installation commands for setting up your MongoDB instance in your preferred environment.
Recommended
Please use the files docker-compose-deploy-dev
and docker-compose-deploy-prod
as examples for you to deploy Nota in a production environment. In those files,
you will see that we pull either the development or production Docker images of
Nota. We set the environment variables needed and configured Watchtower
to update our running containers when it detects a new image is available for
the dev or prod environments. I suggest putting a proxy server in front of the
Docker setup, such as NGINX.
This option assumes you would like to deploy Nota in an environment without Docker.
Please make sure you read through the Docker files in this repository to make sure
the environment you choose to install Nota has the correct dependencies and configuration.
Please note, you will have to install forever
via npm
globally. I won't be
officially supporting this deployment option.
-
Run
./scripts/production.sh
to start the server. The script callsforever
to start and monitor the server. -
If you need to kill
forever
for any reasons, runforever list
. You will then see a list of allforever
processes. Kill theforever
process you want by identifying thepid
and killing it by runningforever stop pidNUM
where pidNUM is the pid number is the process you would like to kill. -
By default, the server will be listening on port 3000.
-
Forever makes sure a node application stays running if something were to cause it to be killed.
-
If you want, when deploying to a server, use NGINX as a proxy in front of Nota. There are many benefits of doing so.
This is mandatory for a production environment. By default, code in Nota does
not expect authentication to be handled for test and development environments.
To use test and development environment with MongoDB authentication,
go to scripts/test.sh
and scripts/development.sh
and make modifications to the line
exporting the DATABASEURI
.
Note: When dropping collections or databases with a new user attached to it, that new user may not be able to drop the database. Consult MongoDB documentation for more info. The below instructions assumes you are not using a managed MongoDB service and you are installing and setting up MongoDB yourself in your preferred environment.
Note, in production, please use a unique username and strong password for everything.
1.) Enter the mongo shell by running mongo
.
2.) Need to create a user that has elevated privileges.
use admin
db.createUser(
{
user: "root",
pwd: "<your-own-password>",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
3.) Run db.adminCommand('getCmdLineOpts');
to find your config file path.
3.) Exit out of the mongo shell.
4.) Go to your mongodb.conf
file and uncomment the line #auth = true
. Save
the file.
5.) Run sudo service mongodb restart
.
6.) Login as admin and connect to authentication database.
mongo -u "root" -p "<your-own-password>" --authenticationDatabase "admin"
7.) Specify the database you would like to enable authentication for.
The username and password URI in scripts/production.sh
can be used for reference
for the commands below.
Run use nota-test
, where nota-test is the database.
db.createUser(
{
user: "nota-test",
pwd: "nota-test",
roles: [ "readWrite"]
})
If you ever encounter MongoDB being locked and is returning no response to Nota, run these commands below.
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
By default, emails are deactivated in Nota. Unit tests will run fine without sending emails unless you activate Nota to send emails. To activate emails, you must do the following below for testing:
export ACTIVATE_EMAIL=true
export MAILGUN_API_KEY=<"your mailgun api key value">
export MAILGUN_DOMAIN=<"your mailgun domain value">
export TEST_EMAIL=<"your verified test email">
Running tests after activating emails and providing the correct test email, emails will be sent to your inbox if you have configured everything correctly with Mailgun.
When you have set Nota up for production, provide the necessary information as
above, as well, export your RESET_URI
.
export RESET_URI=<"your determined reset uri">
If you would like to change the subject or content of the emails being sent, you
may do so in config/default.js
.
I recommend testing sending emails to yourself in Mailgun's sandbox mode before implementing emails for production. You may find more information about Mailgun on it's site.
This backend allows the user to register, login, logout, reset password, create tasks, retrieve tasks, edit tasks, and delete tasks.
All contributions are welcomed! Please read the CONTRIBUTIONS.md
file.
Special Thanks to @julianpoy for making the foundation of this express app. This code base was derived from here. Special Thanks to @cheriejw for providing Nota's logo.
Made with ♥ in Los Angeles & Long Beach CA.